Sha256: 5309553c043cd3f8e7159f19a74bccd5c96dab019b52c2d1988b93ea746e6126

Contents?: true

Size: 1.69 KB

Versions: 20

Compression:

Stored size: 1.69 KB

Contents

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

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

  def show(id)
    @<%= singular_model %> = <%= model_class_name %>.get(id)
    raise NotFound unless @<%= singular_model %>
    display @<%= singular_model %>
  end

  def new
    only_provides :html
    @<%= singular_model %> = <%= model_class_name %>.new
    display @<%= singular_model %>
  end

  def edit(id)
    only_provides :html
    @<%= singular_model %> = <%= model_class_name %>.get(id)
    raise NotFound unless @<%= singular_model %>
    display @<%= singular_model %>
  end

  def create(<%= singular_model %>)
    @<%= singular_model %> = <%= model_class_name %>.new(<%= singular_model %>)
    if @<%= singular_model %>.save
      redirect resource(@<%= singular_model %>), :message => {:notice => "<%= model_class_name %> was successfully created"}
    else
      message[:error] = "<%= model_class_name %> failed to be created"
      render :new
    end
  end

  def update(id, <%= singular_model %>)
    @<%= singular_model %> = <%= model_class_name %>.get(id)
    raise NotFound unless @<%= singular_model %>
    if @<%= singular_model %>.update_attributes(<%= singular_model %>)
       redirect resource(@<%= singular_model %>)
    else
      display @<%= singular_model %>, :edit
    end
  end

  def destroy(id)
    @<%= singular_model %> = <%= model_class_name %>.get(id)
    raise NotFound unless @<%= singular_model %>
    if @<%= singular_model %>.destroy
      redirect resource(:<%= plural_model %>)
    else
      raise InternalServerError
    end
  end

end # <%= class_name %>
<% end -%>

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
merb_datamapper-0.9.10 lib/generators/templates/resource_controller.rb
merb_datamapper-0.9.11 lib/generators/templates/resource_controller.rb
merb_datamapper-0.9.12 lib/generators/templates/resource_controller.rb
merb_datamapper-0.9.13 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.2 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.3 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.4 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.5 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.6 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.6.1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.7 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.7.1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.8 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.8.1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.9 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.10 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.11 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.12 lib/generators/templates/resource_controller.rb