Created
November 1, 2012 06:25
-
-
Save denispeplin/3992175 to your computer and use it in GitHub Desktop.
Add display_filter option to simple_form
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 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working example here: https://github.com/denispeplin/display_filter_demo