开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜