由于CanCan授权,我的部分未加载。如何调试? [英] My partial wasn't loading because of CanCan authorization. How can I debug that?
问题描述
我正在这个问题试图通过来自用户视图的异步请求来呈现部分。
I was having this problem trying to render a partial via an asynchronous request from my users views.
问题是CanCan没有授权调用,因为它在里面一个我在* user_controller.rb *上创建的新动作。我是Rails的新手,我以为在能力类上放了:编辑
。
The problem was that CanCan was not authorizing the call, because it was inside a new action that I created on *user_controller.rb*. I am new to Rails and I thought that putting :edit
on the ability class was enough.
我抓住了因为我从我的链接中删除了 remote:true
,所以它可以通过http请求呈现视图。不要像我这样做。 Begginer的运气!
I caught this error because I removed the remote: true
from my link, so it can render the view via a http request. Don't as me why I did that. Begginer's luck!
我的问题是:如果不幸运,我该怎么调试错误?
My question is: how could I have debugged that error if not by luck?
推荐答案
您可以添加占该部分渲染的测试用例,例如(使用rspec):
You could have added test cases that accounted for the rendering of that partial, for instance (with rspec):
response.should render_template(:partial => 'partial_name')
这篇关于由于CanCan授权,我的部分未加载。如何调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!