Skip to content

Instantly share code, notes, and snippets.

@denispeplin
Created November 1, 2012 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denispeplin/3992175 to your computer and use it in GitHub Desktop.
Save denispeplin/3992175 to your computer and use it in GitHub Desktop.
Add display_filter option to simple_form
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder
# tried to monkey patch without copy'n'pasting, broke associations
def input(attribute_name, options={}, &block)
options = @defaults.deep_dup.deep_merge(options) if @defaults
chosen =
if name = options[:wrapper]
name.respond_to?(:render) ? name : SimpleForm.wrapper(name)
else
wrapper
end
# here display_filter logic begins
display_filter = options.delete(:display_only)
if (! display_filter) || (display_filter && display_filter.include?(attribute_name))
chosen.render find_input(attribute_name, options, &block)
end
end
end
end
@denispeplin
Copy link
Author

# display display_only attributes
if display_filter
  super if display_filter.include?(attribute_name)
else
  super
end

Working example here: https://github.com/denispeplin/display_filter_demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment