lib/generators/templates/resource_controller.rb in merb_datamapper-0.9.8 vs lib/generators/templates/resource_controller.rb in merb_datamapper-0.9.9

- old
+ new

@@ -5,54 +5,54 @@ def index @<%= plural_model %> = <%= model_class_name %>.all display @<%= plural_model %> end - def show - @<%= singular_model %> = <%= model_class_name %>.get(<%= params_for_get %>) + 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 - render + display <%= model_class_name %> end - def edit + def edit(id) only_provides :html - @<%= singular_model %> = <%= model_class_name %>.get(<%= params_for_get %>) + @<%= singular_model %> = <%= model_class_name %>.get(id) raise NotFound unless @<%= singular_model %> - render + display @<%= singular_model %> end - def create + def create(<%= singular_model %>) @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>]) if @<%= singular_model %>.save - redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>) + redirect resource(@<%= singular_model %>), :message => {:notice => "<%= model_class_name %> was successfully created"} else render :new end end - def update - @<%= singular_model %> = <%= model_class_name %>.get(<%= params_for_get %>) + def update(<%= singular_model %>) + @<%= singular_model %> = <%= model_class_name %>.get(<%= singular_model %>[:id] ) raise NotFound unless @<%= singular_model %> - if @<%= singular_model %>.update_attributes(params[:<%= singular_model %>]) || !@<%= singular_model %>.dirty? - redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>) + if @<%= singular_model %>.update_attributes(<%= singular_model %>) + redirect resource(@<%= singular_model %>) else - raise BadRequest + display @<%= singular_model %>, :edit end end - def destroy - @<%= singular_model %> = <%= model_class_name %>.get(<%= params_for_get %>) + def destroy(id) + @<%= singular_model %> = <%= model_class_name %>.get(id) raise NotFound unless @<%= singular_model %> if @<%= singular_model %>.destroy - redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>) + redirect resource(@<%= plural_model %>) else - raise BadRequest + raise InternalServerError end end end # <%= class_name %> <% end -%>