# File lib/active_scaffold/actions/nested.rb, line 130 def add_existing do_add_existing respond_to_action(:add_existing) end
# File lib/active_scaffold/actions/nested.rb, line 135 def destroy_existing return redirect_to(params.merge(:action => :delete)) if request.get? do_destroy_existing respond_to_action(:destroy_existing) end
# File lib/active_scaffold/actions/nested.rb, line 125 def new_existing do_new respond_to_action(:new_existing) end
# File lib/active_scaffold/actions/nested.rb, line 152 def add_existing_respond_to_html if successful? flash[:info] = as_(:created_model, :model => @record.to_label) return_to_main else render(:action => 'add_existing_form') end end
# File lib/active_scaffold/actions/nested.rb, line 160 def add_existing_respond_to_js if successful? render :action => 'add_existing' else render :action => 'form_messages' end end
# File lib/active_scaffold/actions/nested.rb, line 170 def add_existing_respond_to_json render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end
# File lib/active_scaffold/actions/nested.rb, line 167 def add_existing_respond_to_xml render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end
# File lib/active_scaffold/actions/nested.rb, line 173 def add_existing_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end
# File lib/active_scaffold/actions/nested.rb, line 204 def after_create_save(record) if params[:association_macro] == :has_and_belongs_to_many params[:associated_id] = record do_add_existing end end
# File lib/active_scaffold/actions/nested.rb, line 176 def destroy_existing_respond_to_html flash[:info] = as_(:deleted_model, :model => @record.to_label) return_to_main end
# File lib/active_scaffold/actions/nested.rb, line 181 def destroy_existing_respond_to_js render(:action => 'destroy') end
# File lib/active_scaffold/actions/nested.rb, line 189 def destroy_existing_respond_to_json render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end
# File lib/active_scaffold/actions/nested.rb, line 185 def destroy_existing_respond_to_xml render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end
# File lib/active_scaffold/actions/nested.rb, line 193 def destroy_existing_respond_to_yaml render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end
The actual “#add_existing” algorithm
# File lib/active_scaffold/actions/nested.rb, line 212 def do_add_existing parent_record = nested_parent_record(:update) @record = active_scaffold_config.model.find(params[:associated_id]) if parent_record && @record parent_record.send(nested.association.name) << @record parent_record.save else false end end
# File lib/active_scaffold/actions/nested.rb, line 223 def do_destroy_existing if active_scaffold_config.nested.shallow_delete @record = nested_parent_record(:update) collection = @record.send(nested.association.name) assoc_record = collection.find(params[:id]) collection.delete(assoc_record) else do_destroy end end
# File lib/active_scaffold/actions/nested.rb, line 142 def new_existing_respond_to_html if successful? render(:action => 'add_existing_form') else return_to_main end end
# File lib/active_scaffold/actions/nested.rb, line 149 def new_existing_respond_to_js render(:partial => 'add_existing_form') end
# File lib/active_scaffold/actions/nested.rb, line 121 def self.included(base) super end