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
| #Simple form Input class for a hash | |
| class HashInput < SimpleForm::Inputs::Base | |
| def input | |
| key = input_html_options.delete(:key) | |
| #override the params to be in the format that rails will auto correlate back to an | |
| # attribute hash with key: value | |
| input_html_options.merge!({:name => "#{self.object_name}[#{attribute_name}][#{key}]"}) | |
| @builder.text_field(attribute_name, input_html_options) | |
| end | |
| end |
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
| #Simple form Input class for arrays | |
| class ArrayInput < SimpleForm::Inputs::Base | |
| def input | |
| #override the attribute name for arrays to allow rails to handle array forms | |
| input_html_options.merge!({:name => "#{self.object_name}[#{attribute_name}][]"}) | |
| @builder.text_field(attribute_name, input_html_options) | |
| end | |
| end |
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 ExtendFields | |
| require "yaml" | |
| private | |
| def extend_fields | |
| dynamic_fields.each { |name, type| self.class.field name, type: type } | |
| end | |
| def dynamic_fields | |
| YAML.load_file( File.join( Rails.root, 'config', 'class_fields', "#{self.class.name.underscore}.yml" ) ) rescue {} |
NewerOlder