Module: Tramway::Inputs::AssociationsHelper
- Included in:
- Tramway::InputsHelper
- Defined in:
- app/helpers/tramway/inputs/associations_helper.rb
Instance Method Summary collapse
- #build_collection_for_association(form_object, property) ⇒ Object
- #build_value_for_association(form_object, property, value) ⇒ Object
- #check_valid_association(full_class_name_association) ⇒ Object
Instance Method Details
#build_collection_for_association(form_object, property) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/tramway/inputs/associations_helper.rb', line 4 def build_collection_for_association(form_object, property) full_class_name_association = form_object.class.full_class_name_association(property) check_valid_association full_class_name_association full_class_name_association.send("#{current_user.role}_scope", current_user.id).map do |obj| decorator_class(full_class_name_association).decorate obj end.sort_by do |association| association.name || "#{association.class.name} ##{association.id}" end end |
#build_value_for_association(form_object, property, value) ⇒ Object
14 15 16 |
# File 'app/helpers/tramway/inputs/associations_helper.rb', line 14 def build_value_for_association(form_object, property, value) form_object.send(property) || form_object.model.send("#{property}_id") || value end |
#check_valid_association(full_class_name_association) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/tramway/inputs/associations_helper.rb', line 18 def check_valid_association(full_class_name_association) unless full_class_name_association Tramway::Error.raise_error( :tramway, :inputs_helpers, :association_params, :defined_with_property_method, property: property ) end return unless full_class_name_association.is_a? Array Tramway::Error.raise_error( :tramway, :inputs_helpers, :association_params, :used_polymorphic_association, property: property ) end |