module ActiveScaffold::Actions::Nested::ChildMethods

Public Class Methods

included(base) click to toggle source
Calls superclass method
# File lib/active_scaffold/actions/nested.rb, line 137
def self.included(base)
  super
end

Public Instance Methods

add_existing() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 146
def add_existing
  do_add_existing
  respond_to_action(:add_existing)
end
destroy_existing() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 151
def destroy_existing
  return redirect_to(params.merge(:action => :delete)) if request.get?
  do_destroy_existing
  respond_to_action(:destroy_existing)
end
new_existing() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 141
def new_existing
  do_new
  respond_to_action(:new_existing)
end

Protected Instance Methods

add_existing_authorized?(record = nil) click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 213
def add_existing_authorized?(record = nil)
  true
end
add_existing_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 168
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
add_existing_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 176
def add_existing_respond_to_js
  if successful?
    render :action => 'add_existing'
  else
    render :action => 'form_messages'
  end
end
add_existing_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 186
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
add_existing_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 183
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
add_existing_respond_to_yaml() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 189
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
after_create_save(record) click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 220
def after_create_save(record)
  if nested and nested.habtm?
    params[:associated_id] = record
    do_add_existing
  end
end
delete_existing_authorized?(record = nil) click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 216
def delete_existing_authorized?(record = nil)
  true
end
destroy_existing_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 192
def destroy_existing_respond_to_html
  flash[:info] = as_(:deleted_model, :model => @record.to_label)
  return_to_main
end
destroy_existing_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 197
def destroy_existing_respond_to_js
  render(:action => 'destroy')
end
destroy_existing_respond_to_json() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 205
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
destroy_existing_respond_to_xml() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 201
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
destroy_existing_respond_to_yaml() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 209
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
do_add_existing() click to toggle source

The actual “add_existing” algorithm

# File lib/active_scaffold/actions/nested.rb, line 228
def do_add_existing
  parent_record = nested_parent_record(:update)
  @record = active_scaffold_config.model[params[:associated_id]]
  if parent_record && @record
    parent_record.send("add_#{nested.association[:name].to_s.singularize}", @record)
  else
    false
  end
end
do_destroy_existing() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 238
def do_destroy_existing
  if active_scaffold_config.nested.shallow_delete
    @record = nested_parent_record(:update)
    @record.send("remove_#{nested.association[:name].to_s.singularize}", params[:id])
  else
    do_destroy
  end
end
new_existing_respond_to_html() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 158
def new_existing_respond_to_html
  if successful?
    render(:action => 'add_existing_form')
  else
    return_to_main
  end
end
new_existing_respond_to_js() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 165
def new_existing_respond_to_js
  render(:partial => 'add_existing_form')
end

Private Instance Methods

add_existing_formats() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 250
def add_existing_formats
  (default_formats + active_scaffold_config.formats).uniq
end
destroy_existing_formats() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 253
def destroy_existing_formats
  (default_formats + active_scaffold_config.formats).uniq
end
new_existing_formats() click to toggle source
# File lib/active_scaffold/actions/nested.rb, line 247
def new_existing_formats
  (default_formats + active_scaffold_config.formats).uniq
end