Sha256: 768b45b28393af4645fc520abdd8fb74a2441dfababd7a4666bc5131d2219355

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

<% with_modules(controller_modules) do -%>
class <%= controller_class_name %> < Application
  # provides :xml, :yaml, :js

  def index
    @<%= plural_model %> = <%= model_class_name %>.all
    display @<%= plural_model %>
  end

  def show
    @<%= singular_model %> = <%= model_class_name %>[params[:id]]
    raise NotFound unless @<%= singular_model %>
    display @<%= singular_model %>
  end

  def new
    only_provides :html
    @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
    render
  end

  def create
    @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
    if @<%= singular_model %>.save
      redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
    else
      render :new
    end
  end

  def edit
    only_provides :html
    @<%= singular_model %> = <%= model_class_name %>[params[:id]]
    raise NotFound unless @<%= singular_model %>
    render
  end

  def update
    @<%= singular_model %> = <%= model_class_name %>[params[:id]]
    raise NotFound unless @<%= singular_model %>
    if @<%= singular_model %>.update(params[:<%= singular_model %>])
      redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
    else
      raise BadRequest
    end
  end

  def destroy
    @<%= singular_model %> = <%= model_class_name %>[params[:id]]
    raise NotFound unless @<%= singular_model %>
    if @<%= singular_model %>.destroy
      redirect url(:<%= (controller_modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
    else
      raise BadRequest
    end
  end

end
<% end -%>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thorero-gen-0.9.4 templates/component/resource_controller/sequel/app/controllers/%file_name%.rb