Module: Acts::ArchiveController::CreateMethods

Defined in:
lib/acts_as_archive_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) create



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/acts_as_archive_controller.rb', line 130

def create
  record = self.class.content_class_name.constantize.new(params[self.class.singular_name.to_sym])

  instance_variable_set("@#{self.class.singular_name}", record)        
  record.parent = @parent_node

  respond_to do |format|
    if @commit_type == 'preview' && record.valid?
      format.html { render :template => 'admin/shared/create_preview', :locals => { :object => record }, :layout => 'admin/admin_preview' }
      format.xml  { render :xml => record, :status => :created, :location => record }
    elsif @commit_type == 'save' && record.save
      format.html { render :template => 'admin/shared/create' }
      format.xml  { render :xml => record, :status => :created, :location => record }
    else
      format.html { render :template => 'admin/shared/new', :locals => { :object => record }, :status => :unprocessable_entity }
      format.xml  { render :xml => record.errors, :status => :unprocessable_entity }
    end
  end
end

- (Object) new



122
123
124
125
126
127
128
# File 'lib/acts_as_archive_controller.rb', line 122

def new
  instance_variable_set("@#{self.class.singular_name}", self.class.content_class_name.constantize.new(params[self.class.singular_name.to_sym]))

  respond_to do |format|
    format.html { render :template => 'admin/shared/new', :locals => { :object => record }}
  end
end