# Noobie problems with helper

**URL:** <https://www.ruby-forum.com/t/noobie-problems-with-helper/58326>\
**Category:** Rails\
**Created:** [April 20, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326 "2006-04-20T17:23:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/1 "2006-04-20T17:23:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/2 "2006-04-20T17:39:18Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, April 20, 2006 10:23 AM  
Subject: [Rails] Noobie problems with helper

---

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/3 "2006-04-20T17:43:12Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/4 "2006-04-20T19:19:12Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/5 "2006-04-20T19:18:22Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![terhorst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@terhorst](https://www.ruby-forum.com/u/terhorst)\
**Post date:** [April 20, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/noobie-problems-with-helper/58326/6 "2006-04-20T19:37:06Z")

</div>

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!
