轨道:在过滤前和放中断 [英] rails: put and interruption in before filter
问题描述
我想这样叫的时候,如果用户没有权限写入must_have_permission_to_write过滤器之前呈现一个消息,说:你不能这样做!而归。
I want a before filter like "must_have_permission_to_write" that when called if user hasn't permission to write renders a message saying "you can't do that!" and return.
但问题是我得到只能渲染或每行动一次重定向当然......
我怎么能停在过滤器之前执行?
谢谢
Problem is I'm getting "can only render or redirect once per action" of course... how can I stop the execution in the before filter? thanks
推荐答案
我觉得最简单的答案就是添加一个重定向并返回false到你的 must_have_permission_to_write
方法。
I think the easiest answer is add a redirect and return false to your must_have_permission_to_write
method.
def must_have_permission_to_write
unless current_user.has_permission?(something)
redirect_to access_denied_path
return false
end
end
然后,创建地方拒绝访问操作,添加路由,并把任何你想在模板中。
Then, create an action for access denied somewhere, add the route, and put whatever you want in the template.
这篇关于轨道:在过滤前和放中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!