Class: Madmin::Field
- Inherits:
-
Object
- Object
- Madmin::Field
- Defined in:
- lib/madmin.rb,
lib/madmin/field.rb,
lib/madmin/field/text.rb,
lib/madmin/field/email.rb,
lib/madmin/field/number.rb,
lib/madmin/field/select.rb,
lib/madmin/field/has_one.rb,
lib/madmin/field/has_many.rb,
lib/madmin/field/password.rb,
lib/madmin/field/check_box.rb,
lib/madmin/field/date_time.rb,
lib/madmin/field/text_area.rb,
lib/madmin/field/belongs_to.rb,
lib/madmin/field/polymorphic.rb,
lib/madmin/field/associatable.rb
Direct Known Subclasses
BelongsTo, CheckBox, DateTime, Email, HasMany, HasOne, Number, Password, Polymorphic, Select, Text, TextArea
Defined Under Namespace
Modules: Associatable Classes: BelongsTo, CheckBox, DateTime, Email, HasMany, HasOne, Number, Password, Polymorphic, Select, Text, TextArea
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#show ⇒ Object
readonly
Returns the value of attribute show.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(args) ⇒ Field
constructor
A new instance of Field.
-
#strong_params_keys ⇒ Object
Returns an array of key(s) to use in strong params for the resources controller.
-
#to_partial_path ⇒ Object
Returns the partial path for the field type.
-
#value_for(resource) ⇒ Object
Returns the value for a given resource.
Constructor Details
#initialize(args) ⇒ Field
Returns a new instance of Field.
12 13 14 15 16 17 18 19 20 |
# File 'lib/madmin/field.rb', line 12 def initialize(args) @key = args[:key] = args @model = args[:model] @label = option_or_default(:label, label_from_attribute(key)) @form = option_or_default(:form, false) @index = option_or_default(:index, false) @show = option_or_default(:show, true) end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
3 4 5 |
# File 'lib/madmin/field.rb', line 3 def form @form end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
4 5 6 |
# File 'lib/madmin/field.rb', line 4 def index @index end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/madmin/field.rb', line 5 def key @key end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/madmin/field.rb', line 6 def label @label end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/madmin/field.rb', line 7 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/madmin/field.rb', line 8 def end |
#show ⇒ Object (readonly)
Returns the value of attribute show.
9 10 11 |
# File 'lib/madmin/field.rb', line 9 def show @show end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/madmin/field.rb', line 10 def type @type end |
Instance Method Details
#strong_params_keys ⇒ Object
Returns an array of key(s) to use in strong params for the resources controller.
25 26 27 |
# File 'lib/madmin/field.rb', line 25 def strong_params_keys [key] end |
#to_partial_path ⇒ Object
Returns the partial path for the field type
31 32 33 |
# File 'lib/madmin/field.rb', line 31 def to_partial_path "madmin/fields/#{self.class.to_s.split("Madmin::Field::").last.underscore}" end |
#value_for(resource) ⇒ Object
Returns the value for a given resource
37 38 39 |
# File 'lib/madmin/field.rb', line 37 def value_for(resource) resource.send(key) end |