Redirect on catching an exception in a method in the model

你。 提交于 2019-12-06 01:26:58

Hmm, well you could put a method that handles the error that has_token? throws, and tell your controller to redirect that exact error. something like this in your controller:

rescue_from OauthError::RecordNotFound, :with => :deny_access then you can put



def deny_access
  redirect_to your_view_path, :alert => "Too bad sucker" #some flash message
end

Or you could do something like this in the controller:


if complete_oauth_transaction.errors.present?
  redirect_to your_view_path
else
  # continue on with the normal code here
end

This is how you could generically handle errors. Your exact code will vary, as this is all we have to go off of.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!