I have the following helper method in application_helper.rb: def format_date(date) day = to_s(date.day) month = to_s(date.month) time = to_s(date.time) date = day + "/" + month + " - " + time return date end I am trying to call this method in a view like this: <%= format_date(bounty.created_on) %> create_on is a timestamp in mysql. I am getting this error: ArgumentError in Bounties#index Showing app/views/bounties/list.rhtml where line #14 raised: wrong number of arguments (1 for 0) Extracted source (around line #14): 11: <tr> 12: <td><%= bounty.bounty %></td> 13: <td><%= bounty.customer.first_name %></td> 14: <td><%= format_date(bounty.created_on) %></td> 15: <td><%= link_to ''Show'', :action => ''show'', :id => bounty %></td> 16: <td><%= link_to ''Edit'', :action => ''edit'', :id => bounty %></td> 17: <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => bounty }, :confirm => ''Are you sure?'', :post => true %></td> I am a ruby, rails, and programming newbie so I''m sure there is just a simple syntax error. Thanks for the help in advance. -- Posted via http://www.ruby-forum.com/.
Hi Jonathan, I notice your code below uses "bounty.created_on" but you say just below that "create_on" is a timestamp in mysql". If that''s not just a typo (i.e., created_on vs. create_on), that''s one place to look. hth, Bill ----- Original Message ----- From: "Jonathan Towell" <jrtowell@gmail.com> To: <rails@lists.rubyonrails.org> Sent: Thursday, April 20, 2006 10:23 AM Subject: [Rails] Noobie problems with helper>I have the following helper method in application_helper.rb: > > def format_date(date) > day = to_s(date.day) > month = to_s(date.month) > time = to_s(date.time) > > date = day + "/" + month + " - " + time > return date > end > > I am trying to call this method in a view like this: > > <%= format_date(bounty.created_on) %> > > create_on is a timestamp in mysql. I am getting this error: > > ArgumentError in Bounties#index > Showing app/views/bounties/list.rhtml where line #14 raised: > wrong number of arguments (1 for 0) > Extracted source (around line #14): > > 11: <tr> > 12: <td><%= bounty.bounty %></td> > 13: <td><%= bounty.customer.first_name %></td> > 14: <td><%= format_date(bounty.created_on) %></td> > 15: <td><%= link_to ''Show'', :action => ''show'', :id => bounty %></td> > 16: <td><%= link_to ''Edit'', :action => ''edit'', :id => bounty %></td> > 17: <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => bounty > }, :confirm => ''Are you sure?'', :post => true %></td> > > I am a ruby, rails, and programming newbie so I''m sure there is just a > simple syntax error. Thanks for the help in advance. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> I notice your code below uses "bounty.created_on" but you say just below > that "create_on" is a timestamp in mysql". If that''s not just a typo > (i.e., > created_on vs. create_on), that''s one place to look.sry, I meant to say that created_on is the timestamp in mysql. That was a typo in my post, but should be correct in the code. -- Posted via http://www.ruby-forum.com/.
> > def format_date(date) > day = to_s(date.day) > month = to_s(date.month) > time = to_s(date.time) > > date = day + "/" + month + " - " + time > return date > endThe error is in your call of the to_s function. if you really want to format the call it as a method instead: date.day.to_s (Also, trying to call date.time isn''t going to work.) Maybe you should try date.strftime instead of rolling your own handler? Matt -- Posted via http://www.ruby-forum.com/.
> if you really want to > format the call it as a method instead: date.day.to_s (Also, trying toUm, that should just read "Call it as a method instead ..." Matt -- Posted via http://www.ruby-forum.com/.