Rails Tag Helper default values

I was tooling through a form setting text_field sizes ( the default of :size => 30 is a bit big for me ) and my “cut-n-paste is bad” alarm when off. There had to be a better way to set the form tag defaults. A few minutes on Google and Noobkit provided an answer:

InstanceTag::DEFAULT_*

For instance,

ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS = { :size => 15 }

in my environment.rb sets the size of all undefined textboxes to 15 instead of the default of 30. Other defaults include:

{ :discard_type => true }.freeze unless const_defined?(:DEFAULT_DATE_OPTIONS)

{ "size" => 30 }.freeze unless const_defined?(:DEFAULT_FIELD_OPTIONS)

{ }.freeze unless const_defined?(:DEFAULT_RADIO_OPTIONS)

{ "cols" => 40, "rows" => 20 }.freeze unless const_defined?(:DEFAULT_TEXT_AREA_OPTIONS)

Leave a Reply

You must be logged in to post a comment.