Sha256: 1ac152e82d7b590a76df591ad009d11ad3569892f3ded9137446ec0cd180ce16

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 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(<%= singular_model %>)
       redirect resource(@<%= singular_model %>), :message => {:notice => "<%= model_class_name %> was successfully updated"}
    else
      message[:error] = "<%= model_class_name %> failed to be updated"
      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 %>), :message => {:notice => "<%= model_class_name %> was successfully deleted"}
    else
      raise InternalServerError
    end
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
merb_datamapper-1.1.3 lib/generators/templates/resource_controller.rb
merb_datamapper-1.1.2 lib/generators/templates/resource_controller.rb
merb_datamapper-1.1.1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.1.0 lib/generators/templates/resource_controller.rb
merb_datamapper-1.1.0.rc1 lib/generators/templates/resource_controller.rb
merb_datamapper-1.1.0.pre lib/generators/templates/resource_controller.rb