Gudleik Rasch
2010-Dec-07 07:19 UTC
[Rails] Accessing url_for from a custom helper classccdaææææøøøæøæ"¥00
I have some custom helper classes under lib/ that need to access the routes (link_to/url_for/etc): http://gist.github.com/520529 But when I call <%= magic_link Product.first %> from the view it renders the error -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-07 16:26 UTC
[Rails] Re: Accessing url_for from a custom helper classccdaææææøøøæøæ"¥00
Gudleik Rasch wrote in post #966781:> I have some custom helper classes under lib/ that need to access the > routes (link_to/url_for/etc): > http://gist.github.com/520529 > > But when I call <%= magic_link Product.first %>NEVER DO THAT! Product.first does a database call. Therefore, it should *never* be used in the view. The view should never, ever touch the database under any circumstances. Instead, make the database call in the controller and set an @instance variable. from the view it renders> the errorWhat error? You''ll probably need to include ActionController::UrlWriter in your helper. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.