Created
December 12, 2012 11:44
-
-
Save equivalent/4267176 to your computer and use it in GitHub Desktop.
simple "monkey patch" way how to generate simple_form form with class representing model name ('document_name') and action ('new') ... I'm sure there is better practice to do this but this is fine for my requirement app/helpers/custom_simple_form_helper.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module CustomSimpleFormHelper | |
| def simple_form_for(object, *args, &block) | |
| options = args.extract_options! | |
| action_classes = [object.class.model_name.underscore , (object.persisted? ? 'edit' : 'new')] | |
| options[:html]={} unless options[:html] | |
| if options[:html].empty? | |
| options[:html][:class] = action_classes | |
| else | |
| if options[:html][:class].is_a? String | |
| options[:html][:class] += " #{action_classes.join(' ')}" | |
| elsif options[:html][:class].is_a? Array | |
| options[:html][:class] += action_classes | |
| else | |
| options[:html][:class] = action_classes | |
| end | |
| end | |
| super(object, *(args << options), &block) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment