lib/generators/templates/resource_controller.rb in merb_datamapper-0.9.9 vs lib/generators/templates/resource_controller.rb in merb_datamapper-0.9.10
- old
+ new
@@ -14,31 +14,32 @@
end
def new
only_provides :html
@<%= singular_model %> = <%= model_class_name %>.new
- display <%= model_class_name %>
+ 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(params[:<%= 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(<%= singular_model %>)
- @<%= singular_model %> = <%= model_class_name %>.get(<%= singular_model %>[:id] )
+ 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
@@ -47,10 +48,10 @@
def destroy(id)
@<%= singular_model %> = <%= model_class_name %>.get(id)
raise NotFound unless @<%= singular_model %>
if @<%= singular_model %>.destroy
- redirect resource(@<%= plural_model %>)
+ redirect resource(:<%= plural_model %>)
else
raise InternalServerError
end
end