Hi, everything is in the title... I''ve got a function declared in my controller... I want to access it from a helper. I copied/pasted the function in the controller and the helper and it works... But as Rails is "DRY", I''d like to find a better way... Thanks. Nicolas. -- 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 -~----------~----~----~----~------~----~------~--~---
It sounds like the method you want to call isn''t actually a public method? Otherwise calling it from a helper wouldn''t make sense. If it''s a "helper" method you want to call, then I''d suggest moving it into lib/. On 28/08/06, Nicolas Blanco <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > everything is in the title... I''ve got a function declared in my > controller... I want to access it from a helper. I copied/pasted the > function in the controller and the helper and it works... But as Rails > is "DRY", I''d like to find a better way... > > Thanks. > Nicolas. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2006-Aug-28 20:36 UTC
Re: How can I access a controller method from a helper ?
You''ll have to find another place to put the function, or make an Ajax call to that controller action when the page loads. A suggestion: if it''s tied to the model you''re using, put the function in the model. Jason On 8/28/06, Nicolas Blanco <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > everything is in the title... I''ve got a function declared in my > controller... I want to access it from a helper. I copied/pasted the > function in the controller and the helper and it works... But as Rails > is "DRY", I''d like to find a better way... > > Thanks. > Nicolas. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2006-Aug-28 20:48 UTC
Re: How can I access a controller method from a helper ?
On 8/28/06, Nicolas Blanco <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > everything is in the title... I''ve got a function declared in my > controller... I want to access it from a helper. I copied/pasted the > function in the controller and the helper and it works... But as Rails > is "DRY", I''d like to find a better way...In your controller, helper_method :mymethod See http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html#M000139 jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2006-Aug-28 20:58 UTC
Re: How can I access a controller method from a helper ?
Ah yes, another good suggestion. If it''s a method used in many places, it may belong in another class entirely and can reside in lib/ Jason On 8/28/06, Ian Leitch <port001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > It sounds like the method you want to call isn''t actually a public method? > Otherwise calling it from a helper wouldn''t make sense. If it''s a "helper" > method you want to call, then I''d suggest moving it into lib/. > > > On 28/08/06, Nicolas Blanco <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > > Hi, > > > > everything is in the title... I''ve got a function declared in my > > controller... I want to access it from a helper. I copied/pasted the > > function in the controller and the helper and it works... But as Rails > > is "DRY", I''d like to find a better way... > > > > Thanks. > > Nicolas. > > > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Matt von rohr
2006-Aug-29 12:05 UTC
Re: How can I access a controller method from a helper ?
What about if you put it into the model (presuming it does not have controller or view specific code). Maybe you can elaborate a little more on the purpose of your function kind regards Matt _____ www.matthiasvonrohr.ch --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---