Skip to content

Commit

Permalink
Halting page with 404, if record is not found, by default
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Max committed Jul 1, 2012
1 parent 98eb032 commit a7b6b69
Showing 1 changed file with 21 additions and 9 deletions.
Expand Up @@ -22,26 +22,38 @@ Admin.controllers :<%= @orm.name_plural %> do


get :edit, :with => :id do get :edit, :with => :id do
@<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %> @<%= @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 end


put :update, :with => :id do put :update, :with => :id do
@<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %> @<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %> if @<%= @orm.name_singular %>
flash[:notice] = '<%= @orm.klass_name %> was successfully updated.' if <%= @orm.update_attributes("params[:#{@orm.name_singular}]") %>
redirect url(:<%= @orm.name_plural %>, :edit, :id => @<%= @orm.name_singular %>.id) 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 else
render '<%= @orm.name_plural %>/edit' halt 404
end end
end end


delete :destroy, :with => :id do delete :destroy, :with => :id do
<%= @orm.name_singular %> = <%= @orm.find("params[:id]") %> <%= @orm.name_singular %> = <%= @orm.find("params[:id]") %>
if <%= @orm.destroy %> if <%= @orm.name_singular %>
flash[:notice] = '<%= @orm.klass_name %> was successfully destroyed.' 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 else
flash[:error] = 'Unable to destroy <%= @orm.klass_name %>!' halt 404
end end
redirect url(:<%= @orm.name_plural %>, :index)
end end
end end

0 comments on commit a7b6b69

Please sign in to comment.