I need to have the exact same method available in all controllers and in all views. Right now, I have it repeated in app/controllers/ application_controller.rb and app/helpers/application_helper.rb. In DRY tradition, what''s the best way to only have it in one place? TIA, Craig -- 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.
Just put it in a helper and include that helper in ApplicationController like this include MyHelperWithGlobalStuffInIt On Sat, Feb 27, 2010 at 3:08 PM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to have the exact same method available in all controllers and > in all views. Right now, I have it repeated in app/controllers/ > application_controller.rb and app/helpers/application_helper.rb. In > DRY tradition, what''s the best way to only have it in one place? > TIA, > Craig > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
On Feb 27, 5:10 pm, ben wiseley <wisel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just put it in a helper and include that helper in ApplicationController > like this > > include MyHelperWithGlobalStuffInIt >You''re right, putting include ApplicationHelper into application_controller.rb does the trick. But wasn''t that what helper :all # include all helpers, all the time was supposed to do? Or do I misunderstand? -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ve wondered about that too. That doesn''t work for me either. It doesn''t raise an error but doesn''t include :all either. On Sat, Feb 27, 2010 at 4:38 PM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 27, 5:10 pm, ben wiseley <wisel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Just put it in a helper and include that helper in ApplicationController > > like this > > > > include MyHelperWithGlobalStuffInIt > > > You''re right, putting > > include ApplicationHelper > > into application_controller.rb does the trick. > > But wasn''t that what > > helper :all # include all helpers, all the time > > was supposed to do? > > Or do I misunderstand? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
On Feb 28, 12:38 am, Dudebot <craign...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 27, 5:10 pm, ben wiseley <wisel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just put it in a helper and include that helper in ApplicationController > > like this > > > include MyHelperWithGlobalStuffInIt > > You''re right, putting > > include ApplicationHelper > > into application_controller.rb does the trick. > > But wasn''t that what > > helper :all # include all helpers, all the time > > was supposed to do? > > Or do I misunderstand?You do :-). The helper method controls which of your helpers (in app/ helpers) are available to the views for that controller. Without the helper :all call, by default views rendered by foo_controller will get helper methods from foo_helper. You can name specific modules, so for example if you a bunch of common helpers in app/helpers/ common_helpers.rb then you say helper :common_helpers or helper CommonHelpers to add that module for the controller in question. helper :all means add all of the helpers from app/helpers to all of your views. Another way of solving the original problem is declaring the method in application_controller and then saying helper_method :some_helper which takes the named controller method and makes it into a view helper. Fred -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > Or do I misunderstand? > > You do :-). The helper method controls which of your helpers (in app/ > helpers) are available to the views for that controller.Ahhhhh. So *that''s* what it''s there for! :)> Another way of solving the original problem is declaring the method in > application_controller and then saying > > helper_method :some_helper > > which takes the named controller method and makes it into a view > helper.Thanks! Craig -- 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.