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:


12: <%= bounty.bounty %>
13: <%= bounty.customer.first_name %>
14: <%= format_date(bounty.created_on) %>
15: <%= link_to ‘Show’, :action => ‘show’, :id => bounty %>
16: <%= link_to ‘Edit’, :action => ‘edit’, :id => bounty %>
17: <%= link_to ‘Destroy’, { :action => ‘destroy’, :id => bounty
}, :confirm => ‘Are you sure?’, :post => true %>

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.

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” [email protected]
To: [email protected]
Sent: Thursday, April 20, 2006 10:23 AM
Subject: [Rails] Noobie problems with helper

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.

if you really want to
format the call it as a method instead: date.day.to_s (Also, trying to

Um, that should just read “Call it as a method instead …”

Matt

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

The 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

good call on strftime. That’s what I’ll do instead. I guess I should
read the ruby manual and not just the rails manual :slight_smile: Thanks for the
help!