Initializer or application_controller? Where should it go?

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?

On Mon, Mar 1, 2010 at 7:07 AM, GoodGets [email protected] 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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs