Ruby on rails 调试坎坎
我正在尝试调试下面的块Ruby on rails 调试坎坎,ruby-on-rails,cancan,Ruby On Rails,Cancan,我正在尝试调试下面的块 can :create, Todo do |todo| todo.user.account == user.account end 我正在使用todocontroller顶部的load\u和\u authorize\u资源 我遇到的问题是执行:create操作时,“account”是上述todo.user.account的nil方法。todo对象在传递时似乎没有完全实例化;我不知道如何控制这一点 以下是TodosController的相关部分: de
can :create, Todo do |todo|
todo.user.account == user.account
end
我正在使用todocontroller
顶部的load\u和\u authorize\u资源
我遇到的问题是执行:create操作时,“account”是上述todo.user.account
的nil方法。todo对象在传递时似乎没有完全实例化;我不知道如何控制这一点
以下是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
然后:
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])
authorize! :create, @todo
然后:
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])
authorize! :create, @todo