Permalink
Browse files

Halting page with 404, if record is not found, by default

  • Loading branch information...
E-Max
E-Max committed Jul 1, 2012
1 parent 98eb032 commit a7b6b69ce9f309e3e8616b3ad2c8f561590f5170
Showing with 21 additions and 9 deletions.
  1. +21 −9 padrino-admin/lib/padrino-admin/generators/templates/page/controller.rb.tt
@@ -22,26 +22,38 @@ Admin.controllers :<%= @orm.name_plural %> do
get :edit, :with => :id do
@<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
render '<%= @orm.name_plural %>/edit'
if @<%= @orm.name_singular %>
render '<%= @orm.name_plural %>/edit'
else
halt 404
end
end
put :update, :with => :id do
@<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %>
flash[:notice] = '<%= @orm.klass_name %> was successfully updated.'
redirect url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id)
if @<%= @orm.name_singular %>
if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %>
flash[:notice] = '<%= @orm.klass_name %> was successfully updated.'
redirect url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id)
else
render '<%= @orm.name_plural %>/edit'
end
else
render '<%= @orm.name_plural %>/edit'
halt 404
end
end
delete :destroy, :with => :id do
<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
if <%= @orm.destroy %>
flash[:notice] = '<%= @orm.klass_name %> was successfully destroyed.'
if <%= @orm.name_singular %>
if <%= @orm.destroy %>
flash[:notice] = '<%= @orm.klass_name %> was successfully destroyed.'
else
flash[:error] = 'Unable to destroy <%= @orm.klass_name %>!'
end
redirect url(:<%= @orm.name_plural %>, :index)
else
flash[:error] = 'Unable to destroy <%= @orm.klass_name %>!'
halt 404
end
redirect url(:<%= @orm.name_plural %>, :index)
end
end

0 comments on commit a7b6b69

Please sign in to comment.