Ruby on Rails problem

Started by
0 comments, last by Kylotan 18 years, 1 month ago
I was following the tutorial posted here: http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf But I got to page #24 where you make a helper method, and the method doesn't work for me. I get this error:

 ArgumentError in Items#list

Showing app/views/items/list.rhtml where line #11 raised:

wrong number of arguments (0 for 1)

Extracted source (around line #11):

8:     <th><%= link_to_image "description", {:action => "list_by_description"}, "alt" => "Sort by Description" %></th>
9:     <th><%= link_to_image "due_date", {:action => "list"}, "alt" => "Sort by Due Date" %></th> 
10:     <th><%= link_to_image "category", {:action => "list_by_category"}, "alt" => "Sory by Category" %></th>
11:     <th><%= show_image "note" %></th>
12:     <th><%= show_image "private" %></th>
13:     <th>&nbsp;</th>
14:     <th>&nbsp;</th>


This is what my list.rhtml file looks like:

<% @heading = "To Do List" %>
<%= start_form_tag :action => 'new' %>

<table>
  <tr>
    <th><%= link_to_image "done", {:action => "purge_completed"}, :confirm => "Are you sure you want to permanently delete all completed To Dos?" %></th>
    <th><%= link_to_image "priority", {:action => "list_by_priority"}, "alt" => "Sort by Priority" %></th>
    <th><%= link_to_image "description", {:action => "list_by_description"}, "alt" => "Sort by Description" %></th>
    <th><%= link_to_image "due_date", {:action => "list"}, "alt" => "Sort by Due Date" %></th> 
    <th><%= link_to_image "category", {:action => "list_by_category"}, "alt" => "Sory by Category" %></th>
    <th><%= show_image "note" %></th>
    <th><%= show_image "private" %></th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
 </tr>
<%= render_collection_of_partials "list_stripes", @items %>
</table>
<hr />
<%= submit_tag "New To Do..." %>
<%= submit_tag "Categories...", {:type => "button", :onClick => "parent.location = '" + url_for(:controller => "categories", :action => "list") + "'"} %>
<%= end_form_tag %>
<%= "Page: " + pagination_links(@item_pages, :params => {:action => @params["action"] || "index"}) + "<hr />" if @item_pages.page_count > 1 %>

And here's application_helper.rb

# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def self.append_features(controller)
    controller.ancestors.include?(ActionController::Base) ?
      controller.add_template_helper(self) : super
  end
  
  def show_image(src)
    img_options = { "src" => src.include?{"/"} ? src : "/images/#{src}"}
    img_options["src"] = img_options["src"] + ".png" unless 
      img_options["src"].include?(".")
    img_options["border"] = "0"
    tag("img", img_options)
  end
end

And I included the Application helper in the application controller

# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  helper :Application
end

What am I doing wrong? I can't understand why I'm getting an error about passing the wrong number of arguments.
Advertisement
I don't think there are nearly enough Ruby users here to give you a decent answer. Your code looks ok to me but I've only ever written 5 lines of Ruby so what would I know? You could try asking on comp.lang.ruby, perhaps. Good luck!

This topic is closed to new replies.

Advertisement