Helpers -- Problem using one

Hi All,

I've got a view "app\views\home\start..rhtml" that invokes a partial
template with:

< %= render :partial => "customer/list" % >

(spaces inserted between % and its associated angle bracket here and in the
following code).

The partial view "app\views\customer\_list.rhtml" creates a link with the

< %= link_to(,

  :controller => 'customer',

  :action => 'show',

  :id =>

% >

I'd like to replace the code in the partial view with a one-line helper:

< %= link_to_customer(c) % >

and define the helper in the module in "app\helpers\customer_helper.rb"

def link_to_customer(c)


      controller => 'customer',

      action => 'show',

      id =>


When I tried this, I got:

undefined method `link_to_customer' for #<#<Class:0x3cb2710>:0x3cb2278>

Any ideas of a way to get this going?

Thanks in advance,


Hi Curtis,

Great explanation!! Especially the alternative options!!

Thanks a lot.

Curtis Summers wrote:

Hi Curtis,

Woops. I'm not out of the woods yet.

I'm assuming you are calling this partial while in the home controller


2) Move your link_to_customer definition to application_helper.rb so it
will be available to all controllers/views.

Chose this option, definition same as before.

Substituted my helper invocation in app\views\customer\_list.rhtml
(line 12) and got error messages (looks like it's looking for 'show'
in home rather than customer folder):

NameError in Home#start

Showing app/views/customer/_list.rhtml where line #12 raised:

undefined local variable or method `action' for

Extracted source (around line #12):

9: <% @customers.each do |c| %>
10: <tr>
11: <td>
12: <%= link_to_customer(c) %>
13: </td>
14: <td align="right"> <%= c.balance %> </td>
15: <td> <%= c.last_issue_dt %> </td>

Maybe I have to shift to the other option. I thought I'd wait to see
if you had an approach to make the chosen option work. Maybe it's not
worth wasting your time on it.

Best wishes,

Hi Curtis,

Thanks again. My excuse (we always need one when we screw up, don't
we), is that I'm a Ruby and Rails newbie. So I'm insufficiently
sensitive to those pesky little colons.

Incidentally, I copied the code I started with from somewhere (but
missed the colons), and that source didn't use any braces to form the
hash. So I left them out to see whether it would work without them,
wish it did.

I infer from this success that the link_to method's prototype requires
a hash and the Ruby interpreter accepts the hash-like elements as
components of the needed hash. Just a theory. No need to spend any more
time on me.

Again, thank you very much for pushing me along.

Best wishes,

Curtis Summers wrote: