Sha256: 9ec6b097ac41495ae69e40ee57dc2d373af6d183d19b9d4ca8e9cd5203842ab8

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

class <%= plural_class_name %>Controller < ApplicationController
  
  def index
    @<%= plural_name %> = <%= class_name %>.find(:all)
  end

  def show
    @<%= singular_name %> = <%= class_name %>.find(params[:id])
  end

  def new
    @<%= singular_name %> = <%= class_name %>.new
  end

  def edit
    @<%= singular_name %> = <%= class_name %>.find(params[:id])
  end

  def create
    @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])

    if @<%= singular_name %>.save
      flash[:notice] = '<%= singular_class_name %> was successfully created.'
    else
      count = @<%= singular_name %>.errors.count
      flash[:notice] = count == 1 ? "There is one error, please correct it." : "There are #{count} errors, please correct them."
      render :action => "new"
    end
  end

  def update
    @<%= singular_name %> = <%= class_name %>.find(params[:id])

    if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
      flash[:notice] = '<%= singular_class_name %> was successfully updated.'
    else
      count = @<%= singular_name %>.errors.count
      flash[:notice] = count == 1 ? "There is one error, please correct it." : "There are #{count} errors, please correct them."
      render :action => "edit"
    end
  end

  def delete
    @<%= plural_name %> = [<%= class_name %>.find(params[:id])].flatten
  end

  def destroy
    @<%= plural_name %> = [<%= class_name %>.find(params[:id])].flatten
    @<%= plural_name %>.map(&:destroy)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reactive-activerecord-0.2.0 reactive_generators/resource/templates/controller.rb