调试康康舞
我正在尝试调试以下块。
can :create, Todo do |todo|
todo.user.account == user.account
end
我在 TodosController
顶部使用 load_and_authorize_resource
。
我遇到的问题是,在执行 :create 操作时,上述 todo.user.account
的“account”是一个 nil 方法。似乎待办事项对象在传递时并未完全实例化;我不知道如何控制这一点。
以下是 TodosController 的相关部分:
def new
#@todo = Todo.new
@todo = current_user.todos.build
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @todo }
end
end
def create
#@todo = Todo.new(params[:todo])
#Build the @todo object including the relations of who's made this todo.
@todo = current_user.todos.build(params[:todo])
@todo.subscriptions.build(:user => current_user, :todo => @todo)
@todo.subscriptions.build(:user => @todo.assignee, :todo => @todo)
respond_to do |format|
if @todo.save
#format.html { redirect_to @todo, :notice => 'Todo was successfully created.' }
Notifier.notify_assignee(@todo,current_user).deliver
format.html { redirect_to :back }
format.json { render :json => @todo, :status => :created, :location => @todo }
else
format.html { render :action => "new" }
format.json { render :json => @todo.errors, :status => :unprocessable_entity }
end
end
end
I'm trying to debug the following block.
can :create, Todo do |todo|
todo.user.account == user.account
end
I'm using load_and_authorize_resource
at the top of TodosController
.
The problem I'm having is that the 'account' is a nil method for the above todo.user.account
when performing the :create action. It seems the todo object isn't fully instantiated when it's passed; I'm not sure how to control this bit.
Here are the relevant sections of the TodosController:
def new
#@todo = Todo.new
@todo = current_user.todos.build
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @todo }
end
end
def create
#@todo = Todo.new(params[:todo])
#Build the @todo object including the relations of who's made this todo.
@todo = current_user.todos.build(params[:todo])
@todo.subscriptions.build(:user => current_user, :todo => @todo)
@todo.subscriptions.build(:user => @todo.assignee, :todo => @todo)
respond_to do |format|
if @todo.save
#format.html { redirect_to @todo, :notice => 'Todo was successfully created.' }
Notifier.notify_assignee(@todo,current_user).deliver
format.html { redirect_to :back }
format.json { render :json => @todo, :status => :created, :location => @todo }
else
format.html { render :action => "new" }
format.json { render :json => @todo.errors, :status => :unprocessable_entity }
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进而:
and then: