我正在尝试调试以下块。
can :create, Todo do |todo|
todo.user.account == user.account
end我在TodosController的顶部使用TodosController。
的问题是,在执行:create操作时,'account‘是上面的todo.user.account的一个零方法。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发布于 2013-07-14 00:26:10
load_and_authorize_resource :except => :create然后:
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, @todohttps://stackoverflow.com/questions/7879221
复制相似问题