hi, within the show action i have somethign like this:
@address = current_user.addresses.find(params[:id])
now, lets assume we have a ‘bad’ user and he changes the url to another ID. therefore he would get something like this:
hi, within the show action i have somethign like this:
@address = current_user.addresses.find(params[:id])
now, lets assume we have a ‘bad’ user and he changes the url to another ID. therefore he would get something like this:
hi, within the show action i have somethign like this:
@address = current_user.addresses.find(params[:id])
now, lets assume we have a ‘bad’ user and he changes the url to another ID. therefore he would get something like this:
ActiveRecord::RecordNotFound
in AddressesController#show
Couldn't find Address with ID=6 AND (`addresses`.user_id = 15) >> so what im asking his how u guys handle those situations.
Someone might come along with a better idea and this is something that I picked up elsewhere and cant really take credit for, but I put something like this in my application controller which globally handles this kind of thing — as well as other unhandled errors. I prefer to throw my errors into a db table just because I find it easier to review and reference than a log…
rescue_from Exception, :with => :rescue_all_exceptions if Rails.env == ‘production’ def rescue_all_exceptions(exception) case exception when ActiveRecord::RecordNotFound render :text => “
when ActionController::RoutingError, ActionController::UnknownController, ActionController::UnknownAction
render :text => "<h2 class='sixteenpt_blue'>The request made was invalid</h2>", :layout => "application", :status => :not_found
else
begin
SystemError.new(:user_id => nil,
:account_id => nil,
:location => nil,
:error => "Undefined exception",
:incidentals => { "controller_name" => controller_name || "",
"action_name" => action_name || "",
"request.request_uri" => request.request_uri || "",
"request.method" => request.method || "",
"request.path" => request.path || "",
"request.parameters.inspect" => request.parameters.inspect || "",
"exception.message" => exception.message || "",
"exception.clean_backtrace" => exception.clean_backtrace || "" }
).save
rescue
# worst case we save it to the error logger
logger.error( "\nWhile processing a #{request.method} request on #{request.path}\n
parameters: #{request.parameters.inspect}\n
#{exception.message}\n#{exception.backtrace.join( "\n" )}\n\n" )
end
render :text => "<h2 class='sixteenpt_blue'>An internal error occurred. Sorry for the inconvenience</h2>", :layout => "application", :status => :internal_server_error
end
end