Sha256: 1d211058c4ff2e4577daa9948870211e532b91502d02f4c134e823eaaa435178
Contents?: true
Size: 1002 Bytes
Versions: 11
Compression:
Stored size: 1002 Bytes
Contents
module Para module Inputs class NestedOneInput < SimpleForm::Inputs::Base def input(wrapper_options = nil) input_html_options[:class] << "nested-one" parent_model = object.class association = object.association(attribute_name) relation = parent_model.reflect_on_association(attribute_name) model = relation.klass unless (resource = object.send(:"#{ attribute_name }")) # Build association without trying to save the new record resource = case association when ActiveRecord::Associations::HasOneAssociation association.replace(model.new, false) else association.replace(model.new) end end template.render( partial: 'para/inputs/nested_one', locals: { form: @builder, model: model, resource: resource, attribute_name: attribute_name } ) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems