How to show AccessDenied errors on the active page with CanCan in Rails3

别说谁变了你拦得住时间么 提交于 2019-12-11 03:22:38

问题


I am trying to find a way to display my flash errors on the active page without the redirect_to method.

By the way, the standard flash[:alert] = exception.message didn't show me any error messages, so I changed it to flash[:error].

Thanks for any advice!

rescue_from CanCan::AccessDenied do |exception|  
    flash[:error] = exception.message  
    redirect_to deadlines_path  
end

回答1:


Try:

rescue_from CanCan::AccessDenied do |exception|
  flash.now[:alert] = exception.message
  render 'something_else'
  return false
end

without a redirect.



来源:https://stackoverflow.com/questions/4767460/how-to-show-accessdenied-errors-on-the-active-page-with-cancan-in-rails3

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