Sha256: 660fb7fb36187697693d6d7d7d608c5a7fe8064e804fc43b588c400422bf770c

Contents?: true

Size: 1.46 KB

Versions: 29

Compression:

Stored size: 1.46 KB

Contents

module ActiveScaffold::Actions
  module Subform
    def edit_associated
      do_edit_associated
      render :action => 'edit_associated', :formats => [:js], :readonly => @column.association.options[:readonly]
    end

    protected

    def do_edit_associated
      @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update)
      if @parent_record.new_record?
        apply_constraints_to_record @parent_record
        create_association_with_parent @parent_record if nested?
      end

      generate_temporary_id(@parent_record, params[:generated_id]) if @parent_record.new_record? && params[:generated_id]
      @column = active_scaffold_config.columns[params[:child_association]]

      # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all.
      @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id]
      if @record
        if (association = active_scaffold_config.columns[params[:child_association]].association.reverse)
          if @record.class.reflect_on_association(association).collection?
            @record.send(association) << @parent_record
          else
            @record.send("#{association}=", @parent_record)
          end
        end
      else
        @record = build_associated(@column.association, @parent_record)
      end
      @scope = params[:scope]
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.42 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.41.1 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.41 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.40 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.39 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.38 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.37 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.36 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.35 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.34 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.33 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.32 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.31 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.30 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.29 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.28 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.27 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.26 lib/active_scaffold/actions/subform.rb
active_scaffold-3.4.25 lib/active_scaffold/actions/subform.rb