plataformatec/simple_form — Issue #360: Small change to 'simple_form_for' helper - generate same css class as 'form_for'
Author: ndbroadbent
Created: 2011-11-10 10:45:11+00:00
State: open

Hi,

I switched a couple of our forms to use `simple_form`, and ran into a tiny problem. The rails `form_for` helper produces a form tag with a css class of `edit_contact`, but `simple_form_for` produces a default css class of `simple_form contact`. This broke a few of our tests, and some of our javascript.

I wrote a small patch to change the default behaviour of simple form. The default css class is now `simple_form #{params[:action]}_contact`.

This change may make it easier for others who are switching from `form_for` to `simple_form_for`.
Please let me know if you would like a pull request (with tests) for this change.

If you are totally against the idea of changing the form's default css class, please feel free to just ignore and close this issue.

Here's what the override looks like, if you are interested:

```ruby
# Changes the default css class for generated forms
# from '' to 'edit_' or 'new_'
# (using params[:action])
module SimpleForm
module ActionViewExtensions
module FormHelper
def css_class_with_action(record, html_options)
css_class = css_class_without_action(record, html_options)
# Return defined class, or prepend controller action.
html_options.key?(:class) ? css_class : [params[:action], css_class].join('_')
end
alias_method_chain :css_class, :action
end
end
end
```