How to prevent caller from continuing after redirect_to in Rails?
I defined a before filter in my controller:
before_filter :find, :only => [:caller]
and I want to catch exceptions in "find" method :
def find
begin
...
res开发者_JS百科cue Exception
redirect_to somewhere
end
end
but how can I prevent the "caller" method from continuing executing ?
If a before_filter
renders or redirects, the execution stops automatically.
Learn more: http://guides.rubyonrails.org/action_controller_overview.html#filters
For ActiveRecord
callbacks like before_validation
, use return false
to stop the record from being saved.
Have you tried return
after the redirect in the rescue?
redirect_to ...
return # <<
end
end
精彩评论