我有两个模型--用户和促销,一个用户可以创建has_many促销,另一个是属于用户的促销,对于我使用的用户,可以设计,因此:
当我删除一个促销时,我希望用户也不能删除其他用户的促销,而只能删除自己的
我必须更换控制器,但怎么换呢?我希望能帮上忙
这是破坏促销活动的控制器。
def destroy
@promotion = Promotion.find(params[:id])
@promotion.destroy
#@promotion = current_user.promotions.destroy
respond_to do |format|
format.html { redirect_to promotions_url, notice:'Promotion was successfully delete.' }
format.json { head :ok }
end
end
end对不起,我的英语!
发布于 2013-05-16 20:28:19
如果current_user也是@promotion的创建者,则交叉校验
def destroy
@promotion = Promotion.find(params[:id])
if @promotion.user == current_user #if user is the owner of that promotion
@promotion.destroy
respond_to do |format|
format.html { redirect_to promotions_url, notice:'Promotion was successfully delete.' }
format.json { head :ok }
end
else
redirect_to root_path
end
endhttps://stackoverflow.com/questions/16596796
复制相似问题