Module: Tramway::Core::Inputs::AssociationsHelper
- Included in:
- Tramway::Core::InputsHelper
- Defined in:
- app/helpers/tramway/core/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 |
# File 'app/helpers/tramway/core/inputs/associations_helper.rb', line 4 def build_collection_for_association(form_object, property) user = defined?(current_user) ? current_user : current_admin full_class_name_association = form_object.class.full_class_name_association(property) check_valid_association full_class_name_association full_class_name_association.active.send("#{user.role}_scope", user.id).map do |obj| decorator_class(full_class_name_association).decorate obj end.sort_by(&:name) end |
#build_value_for_association(form_object, property, value) ⇒ Object
13 14 15 |
# File 'app/helpers/tramway/core/inputs/associations_helper.rb', line 13 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
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/tramway/core/inputs/associations_helper.rb', line 17 def check_valid_association(full_class_name_association) unless full_class_name_association Tramway::Error.raise_error( :tramway, :core, :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, :core, :inputs_helpers, :association_params, :used_polymorphic_association, property: property ) end |