【发布时间】:2022-08-15 09:35:53
【问题描述】:
我有一个表,它使用多态来为 \"AtaPublic\" 或 \"AtaObject\" 添加书签。
在我的销毁中,我不想直接删除favorites.id id 的“收藏夹”,我希望这样的东西来自路线:{{URL}}/favorites/ata_public/2
\"AtaPublic\" 或 \"AtaObject\" 的 id 来执行收藏夹的销毁,而不是 favorite_id 的日期。
问题是,我的销毁控制器应该是什么样子?我的参数设置?这样,它会按收藏夹的 ID 删除。
收藏夹控制器
def destroy
if @favorite.destroy
render json: {success: I18n.t(\"favorite.destroy.success_message\")}, status: 200
else
render json: ErrorMessages.new(error: I18n.t(\"favorite.destroy.error_message\"))
.call, status: 422
end
end
private
def parent_ata_public
return AtaPublic.find_by_id(params[:ata_public_id]) if params[:ata_public_id]
end
def parent_ata_object
return AtaObject.find_by_id(params[:ata_object_id]) if params[:ata_object_id]
end
def set_favorite
begin
@favorite = Favorite.where(user: @current_user).find(parent_ata_public)
rescue
render json: ErrorMessages.new(error: I18n.t(\"favorite.not_found.error_message\")).call, status: 404
end
end
路由中的同一个ID怎么删除? 路线:{{URL}}/favorites/ata_public/2
标签: ruby-on-rails ruby