Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created December 12, 2012 11:44
Show Gist options
  • Select an option

  • Save equivalent/4267176 to your computer and use it in GitHub Desktop.

Select an option

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
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