Sha256: f16fa53940fbb75475bcf03ef5a5b4beacf378cf9a4d09f0857c7b338f4bf036

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 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 %>)
    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

3 entries across 3 versions & 1 rubygems

Version Path
merb_datamapper-1.0.15 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.14 lib/generators/templates/resource_controller.rb
merb_datamapper-1.0.13 lib/generators/templates/resource_controller.rb