I need implements a helper that creates <button>...</button> tag, I need to do some similar to this:
<%= form_for(some_var) do |f| %>
<%= f.submit '+' %>
<% end %>
The helper should work like this:
<%= f.button '+' %>
# Returns
<button type="submit">+</button>
I saw https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/form_tag_helper.rb#L458 but this isn’t implemented in Rails 3.0.7.
What I need to do to implements this helper in my application?
You can create a custom form helper that inherits from FormBuilder to use when creating forms. I created this button method to use with Twitter’s Bootstrap.
Replace ‘Bootstrap’ with whatever fits. (Perhaps CuteAsAButtonBuilder?)
app/helpers/bootstrap_form_builder.rbNow you have two ways to use the builder.
1. DRY for ducks
Every time you build a form that uses the button, you need to specify the builder…
2. DRY for devs
Add the following
app/helpers/application_helper.rbJust call the magic builder…