Forum: Ruby on Rails Noobie problems with helper

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
088898ce0d3d6d1c996ca2e21a3a7680?d=identicon&s=25 Jonathan Towell (jpapa)
on 2006-04-20 17:23
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.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-04-20 17:39
(Received via mailing list)
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
088898ce0d3d6d1c996ca2e21a3a7680?d=identicon&s=25 Jonathan Towell (jpapa)
on 2006-04-20 17:43
> 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.
7917d3e60c657d725001b3a86f226815?d=identicon&s=25 Matt (Guest)
on 2006-04-20 19:18
>
>   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
7917d3e60c657d725001b3a86f226815?d=identicon&s=25 Matt (Guest)
on 2006-04-20 19:19
> 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
088898ce0d3d6d1c996ca2e21a3a7680?d=identicon&s=25 Jonathan Towell (jpapa)
on 2006-04-20 19:37
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 :) Thanks for the
help!
This topic is locked and can not be replied to.