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 code: < %= link_to(c.name, :controller => ''customer'', :action => ''show'', :id => c.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" with: def link_to_customer(c) link_to(c.name, controller => ''customer'', action => ''show'', id => c.id) end 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, Richard --- Env.: WinXP-Pro/SP2, MS VisualStudio.NET Eclipse 3.1.2 Ruby 1.8.2-15 Rails 1.1.4 Java JDK 1.5.0_06 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Richard Lionheart wrote:> I''ve got a view "app\views\home\start..rhtml" that invokes a partial > template with: > < %= render :partial => "customer/list" % > > undefined method `link_to_customer'' for #<#<Class:0x3cb2710>:0x3cb2278>I''m assuming you are calling this partial while in the home controller (or a controller other than the customer controller). Your link_to_customer helper method is not mixed into the home controller, and is therefore not available. You have some choices: 1) Mix-in the customer helper methods into your other controller with ''helper'': helper CustomerHelper 2) Move your link_to_customer definition to application_helper.rb so it will be available to all controllers/views. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Curtis, Great explanation!! Especially the alternative options!! Thanks a lot. Richard Curtis Summers wrote:> Richard Lionheart wrote: > > I''ve got a view "app\views\home\start..rhtml" that invokes a partial > > template with: > > < %= render :partial => "customer/list" % > > > undefined method `link_to_customer'' for #<#<Class:0x3cb2710>:0x3cb2278> > > > I''m assuming you are calling this partial while in the home controller > (or a controller other than the customer controller). Your > link_to_customer helper method is not mixed into the home controller, > and is therefore not available. You have some choices: > > 1) Mix-in the customer helper methods into your other controller with > ''helper'': > > helper CustomerHelper > > 2) Move your link_to_customer definition to application_helper.rb so it > will be available to all controllers/views. > > -- > Posted via http://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Curtis, Woops. I''m not out of the woods yet.> I''m assuming you are calling this partial while in the home controllerRight.> 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 #<#<Class:0x3cd7520>:0x3cd7418> 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, Richard --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Richard wrote:> Hi Curtis, > > Woops. I''m not out of the woods yet.Your link_to usage from above was: def link_to_customer(c) link_to(c.name, controller => ''customer'', action => ''show'', id => c.id) end but should be: def link_to_customer(c) link_to(c.name, {:controller => ''customer'', :action => ''show'', :id => c.id}) end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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, Richard Curtis Summers wrote:> Richard wrote: > > Hi Curtis, > > > > Woops. I''m not out of the woods yet. > > Your link_to usage from above was: > > def link_to_customer(c) > link_to(c.name, > controller => ''customer'', > action => ''show'', > id => c.id) > end > > but should be: > > def link_to_customer(c) > link_to(c.name, {:controller => ''customer'', > :action => ''show'', > :id => c.id}) > end > > -- > Posted via http://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---