Overriding ActionView::Helpers::InstanceTag::DEFAULT_TEXT_AREA_OPTIONS

What is the best way to override some of the FormHelper default options? Right now I'm adding this to the beginning of my environment.rb:

ActionView::Helpers::InstanceTag::DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 80, "rows" => 5 }

Is that the way it's supposed to be done?

Actually, you can override it with the right statements.

The constant is defined as: http://caboo.se/doc/classes/ActionView/Helpers/InstanceTag.html http://caboo.se/doc/classes/ActionView/Helpers/InstanceTag.html DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }.freeze unless const_defined?(:DEFAULT_TEXT_AREA_OPTIONS)

The key is the "unless const_defined?(...)". It says that the constant should be defined and frozen, UNLESS it is aready defined.

How do you define it before ActionView::Helpers::InstanceTag is defined?. Well, just define it at the beginning of environment.rb, however, since neither ActionView, Helpers or InstanceTag is defined yet, we must define them fully with Module/Class...End blocks like this:

module ActionView   module Helpers     class InstanceTag       DEFAULT_TEXT_AREA_OPTIONS = { :cols => 60, :rows => 10 }     end   end end

So, just add the code above at the top of your config/environment.rb, and you should be all set and warning-free. I hope this helps someone.

Gabriel Medina. http://www.dottut.com/