class Object

Public Instance Methods

index() click to toggle source

GET /<%= resource_name_plural %>.json

# File lib/generators/contour/scaffold/templates/controller.rb, line 7
def index
  @order = scrub_order(<%= resource_class_name %>, params[:order], "<%= resource_name_plural %>.name")
  @<%= resource_name_plural %> = <%= resource_class_name %>.current.order(@order).page(params[:page]).per( 40 )
end

# GET /<%= resource_name_plural %>/1
# GET /<%= resource_name_plural %>/1.json
def show
end

# GET /<%= resource_name_plural %>/new
def new
  @<%= resource_name %> = <%= resource_class_name %>.new
end

# GET /<%= resource_name_plural %>/1/edit
def edit
end

# POST /<%= resource_name_plural %>
# POST /<%= resource_name_plural %>.json
def create
  @<%= resource_name %> = <%= resource_class_name %>.new(<%= resource_name %>_params)

  respond_to do |format|
    if @<%= resource_name %>.save
      format.html { redirect_to @<%= resource_name %>, notice: '<%= resource_class_name %> was successfully created.' }
      format.json { render action: 'show', status: :created, location: @<%= resource_name %> }
    else
      format.html { render action: 'new' }
      format.json { render json: @<%= resource_name %>.errors, status: :unprocessable_entity }
    end
  end
end

# PUT /<%= resource_name_plural %>/1
# PUT /<%= resource_name_plural %>/1.json
def update
  respond_to do |format|
    if @<%= resource_name %>.update(<%= resource_name %>_params)
      format.html { redirect_to @<%= resource_name %>, notice: '<%= resource_class_name %> was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @<%= resource_name %>.errors, status: :unprocessable_entity }
    end
  end
end

# DELETE /<%= resource_name_plural %>/1
# DELETE /<%= resource_name_plural %>/1.json
def destroy
  @<%= resource_name %>.destroy

  respond_to do |format|
    format.html { redirect_to <%= resource_name_plural %>_path }
    format.json { head :no_content }
  end
end

private
  # Use callbacks to share common setup or constraints between actions.
  def set_<%= resource_name %>
    @<%= resource_name %> = <%= resource_class_name %>.current.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def <%= resource_name %>_params
    params[:<%= resource_name %>] ||= {}

    [<%= date_columns.collect{|c| ":#{c.name}"}.join(', ') %>].each do |date|
      params[:<%= resource_name %>][date] = parse_date(params[:<%= resource_name %>][date])
    end