# Initializer or application\_controller? Where should it go?

**URL:** <https://www.ruby-forum.com/t/initializer-or-application-controller-where-should-it-go/184338>\
**Category:** Rails\
**Created:** [March 1, 2010, 7:08am UTC](https://www.ruby-forum.com/t/initializer-or-application-controller-where-should-it-go/184338 "2010-03-01T07:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoodGets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@GoodGets](https://www.ruby-forum.com/u/GoodGets)\
**Post date:** [March 1, 2010, 7:08am UTC](https://www.ruby-forum.com/t/initializer-or-application-controller-where-should-it-go/184338/1 "2010-03-01T07:08:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GoodGets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@GoodGets](https://www.ruby-forum.com/u/GoodGets)\
**Post date:** [March 1, 2010, 7:23am UTC](https://www.ruby-forum.com/t/initializer-or-application-controller-where-should-it-go/184338/2 "2010-03-01T07:23:00Z")

</div>

On Mon, Mar 1, 2010 at 7:07 AM, GoodGets [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![GoodGets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@GoodGets](https://www.ruby-forum.com/u/GoodGets)\
**Post date:** [March 1, 2010, 8:08am UTC](https://www.ruby-forum.com/t/initializer-or-application-controller-where-should-it-go/184338/3 "2010-03-01T08:08:39Z")

</div>

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.
