Sha256: c2dbbc6408a4df6d917673423847039bb9e49a6451773649f3b2f7662b0642f7

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

class RowsController < ApplicationController
  require_dependency 'rows_controller/helpers'

  respond_to :html, :xml

  def index
    respond_with(resources)
  end

  def show
    respond_with(resource)
  end

  def new
    respond_with(resource)
  end

  def edit
    respond_with(resource)
  end

  def create
#    merge_bag
    msg = t('ui.created', :model => model_name,
	    :default => "%{model} created.")
    save_and_respond(msg, 'rows/new')
  end

  def update
#    merge_bag
    msg = t('ui.updated', :model => model_name,
	    :default => "%{model} updated.")
    save_and_respond(msg, 'rows/edit')
  end

  def destroy
    resource.destroy
    respond_with(resource) do |format|
      format.html { redirect_to :action => :index }
      format.js   { render :template => 'rows/destroy' }
    end
    flash[:notice] = t('ui.deleted', :model => model_name,
		       :default => "%{model} deleted.")
  end

  def copy
    @_resource = resource.dup
    @_resource.id = nil
    respond_with(resource) do |format|
      format.html { render :action => :new }
    end
  end


 private
  def save_and_respond(notice, failure_template)
    if resource.save
      respond_with(resource)
      flash[:notice] = notice
    else
      respond_with(resource) do |format|
	format.html { render :template => failure_template, :id => resource.id }
	format.xml  { render :xml => resource.errors, :status => :unprocessable_entity }
      end
    end
  end

# May be useful:
#  def multi_deletion
#    items = params[:multi_deletion] || []
#    items -= ['']
#    items.map {|id|  model_class.find(id).destroy }
#    redirect_to :action => :index
#  end

#  def merge_bag
#    self.params = model_class.merge({}, self.params) if model_class.respond_to?(:merge)
#  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rows_controller-0.2.4 app/controllers/rows_controller.rb
rows_controller-0.2.3 app/controllers/rows_controller.rb
rows_controller-0.1.0 app/controllers/rows_controller.rb