Hello, this have been debated few times in the forum but I didn''t found a satisfying solution : my problem is very simple, I have few methods dealing with cookies that are intended to be used in controllers and views. Let say I have the read_cookie() method. Because it deals with the response object putting this method in the /lib directory doesn''t fit nicely because I would need to pass the object method to each call to read_cookie, as in read_cookie(response) If I put read_cookie in a application helper, I can''t use it in the controller and if I put it in the application.rb file I can''t use it from the view So, I''m quite sure there is an elegant solution provided by RoR as usual... But which one ? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
nuno wrote:> Hello, this have been debated few times in the forum but I didn''t found > a satisfying solution : my problem is very simple, I have few methods > dealing with cookies that are intended to be used in controllers and > views. > > Let say I have the read_cookie() method. Because it deals with the > response object putting this method in the /lib directory doesn''t fit > nicely because I would need to pass the object method to each call to > read_cookie, as in read_cookie(response) > > If I put read_cookie in a application helper, I can''t use it in the > controller and if I put it in the application.rb file I can''t use it > from the view > > So, I''m quite sure there is an elegant solution provided by RoR as > usual... But which one ? > > ThanksI mean "I will need to pass the response object to every call to read_cookie or write_cookie" (in the case I use /lib) Still no idea -- 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 -~----------~----~----~----~------~----~------~--~---
define the helper in the controller, and use helper_method maybe? http://groups-beta.google.com/group/rubyonrails-talk/browse_thread/thread/e31977720617b676/8b5dd9e5209e3b3e?lnk=gst&q=view+controller+helper&rnum=1#8b5dd9e5209e3b3e --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can also directly instanciate a Helper object and call a method. example with number_to_currency: Object.new.extend(ActionView::Helpers::NumberHelper).number_to_currency(number, options) but beware that is there are methods of other Helpers methods, they will fail. -- Posted via http://www.ruby-forum.com/.