Sha256: b4153d502fb2241c1476559e2041aa4367af55300eb897c88e555f3bb7c16732

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

<% klass = class_name.singularize -%>
<% ivar = class_name.snake_case.singularize -%>
class <%= class_name %> < Application
  provides :xml, :js, :yaml
  
  def index
    @<%= ivar %>s = <%= klass %>.all
    render @<%= ivar %>s
  end
  
  def show
    @<%= ivar %> = <%= klass %>.find(params[:id])
    render @<%= ivar %>
  end
  
  def new
    only_provides :html
    @<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
    render
  end
  
  def create
    @<%= ivar %> = <%= klass %>.new(params[:<%= ivar %>])
    if @<%= ivar %>.save
      redirect url(:<%= ivar %>, @<%= ivar %>)
    else
      render :action => :new
    end
  end
  
  def edit
    only_provides :html
    @<%= ivar %> = <%= klass %>.find(params[:id])
    render
  end
  
  def update
    @<%= ivar %> = <%= klass %>.find(params[:id])
    if @<%= ivar %>.update_attributes(params[:<%= ivar %>])
      redirect url(:<%= ivar %>, @<%= ivar %>)
    else
      raise BadRequest
    end
  end
  
  def destroy
    @<%= ivar %> = <%= klass %>.find(params[:id])
    if @<%= ivar %>.destroy!
      redirect url(:<%= ivar %>s)
    else
      raise BadRequest
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
merb_data_mapper-0.4.0 data_mapper_generators/resource_controller/templates/controller.rb