On Fri, Dec 3, 2010 at 3:27 PM, tom
<tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 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 => "<h2
class=''sixteenpt_blue''>The requested record was
not found</h2>", :layout => "application", :status =>
:not_found
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
>
> thx
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.