You can create a special form helper that inherits FormBuilder for use in creating forms. I created this button method for use with Twitter Bootstrap.
"Bootstrap" . (, CuteAsAButtonBuilder?)
app/helpers/bootstrap_form_builder.rb
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
def button(label, options={})
default_class = options[:class] || 'btn'
@template.button_tag(label.to_s.humanize, :class => default_class)
end
end
.
1.
, , , ...
<%= form_for @duck, :builder => BootstrapFormBuilder do |form|%>
2. DRY
app/helpers/application_helper.rb
module ApplicationHelper
def bootstrap_form_for(name, *args, &block)
options = args.extract_options!
form_for(name, *(args << options.merge(:builder => BootstrapFormBuilder)), &block)
end
end
...
<%= bootstrap_form_for @person do |form| %>
<%= form.button 'Click Me' %>
<% end %>