Class: SimpleAttribute::Attributes::Association
- Defined in:
- lib/simple_attribute/attributes/association.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #options, #record, #value
Instance Method Summary collapse
-
#attribute_name ⇒ Object
Attribute name.
-
#label_method ⇒ Object
Link label method.
-
#render_attribute ⇒ Object
Render attribute.
-
#title_method ⇒ Object
Link title method.
-
#url_method ⇒ Object
Link url method.
Methods inherited from Base
#default_value, #defaults, #html_options, #initialize, #method_missing, #render, #render_default_value, #render_with_default, #render_wrapper, #renderer_name, #value?, #wrapper, #wrapper?, #wrapper_html
Constructor Details
This class inherits a constructor from SimpleAttribute::Attributes::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SimpleAttribute::Attributes::Base
Instance Method Details
#attribute_name ⇒ Object
Attribute name
5 6 7 |
# File 'lib/simple_attribute/attributes/association.rb', line 5 def attribute_name 'association' end |
#label_method ⇒ Object
Link label method
10 11 12 |
# File 'lib/simple_attribute/attributes/association.rb', line 10 def label_method @options.fetch(:label, :id) end |
#render_attribute ⇒ Object
Render attribute
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simple_attribute/attributes/association.rb', line 25 def render_attribute label = value.try(label_method) title = value.try(title_method) unless url_method.nil? value = @context.send(url_method, @value) end link_to label, value, .merge(title: title) end |
#title_method ⇒ Object
Link title method
15 16 17 |
# File 'lib/simple_attribute/attributes/association.rb', line 15 def title_method @options.fetch(:title, :id) end |
#url_method ⇒ Object
Link url method
20 21 22 |
# File 'lib/simple_attribute/attributes/association.rb', line 20 def url_method @options.fetch(:url, nil) end |