Class: Cms::FormField
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::FormField
- Extended by:
- DefaultAccessible
- Defined in:
- app/models/cms/form_field.rb
Instance Attribute Summary collapse
-
#delete_path ⇒ Object
Returns the value of attribute delete_path.
-
#edit_path ⇒ Object
Returns the value of attribute edit_path.
Class Method Summary collapse
-
.permitted_params ⇒ Object
Don’t allow name to be set via UI.
Instance Method Summary collapse
-
#as ⇒ Symbol
Return the form widget that should be used to render this field.
- #as_json(options = {}) ⇒ Object
-
#options(config = {}) ⇒ Hash
Return options to be passed to a SimpleForm input.
Methods included from DefaultAccessible
non_permitted_params, permitted_params
Instance Attribute Details
#delete_path ⇒ Object
Returns the value of attribute delete_path.
8 9 10 |
# File 'app/models/cms/form_field.rb', line 8 def delete_path @delete_path end |
#edit_path ⇒ Object
Returns the value of attribute edit_path.
8 9 10 |
# File 'app/models/cms/form_field.rb', line 8 def edit_path @edit_path end |
Class Method Details
.permitted_params ⇒ Object
Don’t allow name to be set via UI.
67 68 69 |
# File 'app/models/cms/form_field.rb', line 67 def self.permitted_params super - [:name] end |
Instance Method Details
#as ⇒ Symbol
Return the form widget that should be used to render this field.
28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/cms/form_field.rb', line 28 def as case field_type when "text_field" :string when "text_area" :text else field_type.to_sym end end |
#as_json(options = {}) ⇒ Object
20 21 22 |
# File 'app/models/cms/form_field.rb', line 20 def as_json(={}) super(:methods => [:edit_path, :delete_path]) end |
#options(config = {}) ⇒ Hash
Return options to be passed to a SimpleForm input.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/cms/form_field.rb', line 44 def (config={}) opts = {label: label} if field_type != "text_field" opts[:as] = self.as end if config[:disabled] opts[:disabled] = true opts[:readonly] = 'readonly' end opts[:required] = !!required opts[:hint] = instructions if instructions unless choices.blank? opts[:collection] = parse_choices opts[:prompt] = !self.required? end unless config[:entry] && config[:entry].send(name) opts[:input_html] = {value: default_value} end opts end |