I''m changing how rails handles error messages. So I''m defining ActionView::Base.field_error_proc = Proc.new do etc. Where should I put this? I''ve seen examples putting it in the application_controller, as well as creating a new initializer. Both ways work (at least for me in this case), but which is best? and why? -- 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.
Xavier Noria
2010-Mar-01 06:21 UTC
Re: initializer or application_controller? Where should it go?
On Mon, Mar 1, 2010 at 7:07 AM, GoodGets <goodgets-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m changing how rails handles error messages. So I''m defining > ActionView::Base.field_error_proc = Proc.new do > etc. > > Where should I put this? I''ve seen examples putting it in the > application_controller, as well as creating a new initializer. Both > ways work (at least for me in this case), but which is best? and why?Some people associate the fact that ApplicationController is needed to serve a request with a place to put required global stuff like that. Reason is that they observe the framework loads that file necessarily. (Note that a background job may not trigger any request though.) That is not the role of ApplicationController. That is a class that should be used according to its OO role: it is the root of the controllers hierarchy. In my opinion global stuff like the one you mention belongs to the initializers. -- 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.
GoodGets
2010-Mar-01 07:07 UTC
Re: initializer or application_controller? Where should it go?
That''s exactly what I was thinking (although not quite as eloquently as you stated). I guess just because it "works" doesn''t mean it''s right, and only wondered why others were putting it in their application controller. Just sloppy code I guess. Thank you Xavier. On Mar 1, 1:21 am, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Mon, Mar 1, 2010 at 7:07 AM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''m changing how rails handles error messages. So I''m defining > > ActionView::Base.field_error_proc = Proc.new do > > etc. > > > Where should I put this? I''ve seen examples putting it in the > > application_controller, as well as creating a new initializer. Both > > ways work (at least for me in this case), but which is best? and why? > > Some people associate the fact that ApplicationController is needed to > serve a request with a place to put required global stuff like that. > Reason is that they observe the framework loads that file necessarily. > (Note that a background job may not trigger any request though.) > > That is not the role of ApplicationController. That is a class that > should be used according to its OO role: it is the root of the > controllers hierarchy. > > In my opinion global stuff like the one you mention belongs to the initializers.-- 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.