ruby-on-rails - 使用 has_and_belongs_to_many 时,更新时的浅嵌套不知道父级
问题描述
从文档中,以下用于编辑和更新的路线将类似于 /comments/:id
resources :articles do
resources :comments, shallow: true
end
当我更新评论并且它不知道文章时,您如何返回评论索引?在这种情况下你会回到文章索引吗?
在使用浅嵌套时更新评论后是否有可接受的解决方法来返回评论列表?
更新我的模型使用 has_and_belongs_to_many 关联,因此我无法通过 @comment.article 获取父级。
我的模型
class Venue < ApplicationRecord
has_and_belongs_to_many :users
end
class User < ApplicationRecord
has_and_belongs_to_many :venues
end
我的路线
resources :venues do
resources :accounts, shallow: true
end
解决方案
推荐阅读
- windows - FC 命令问题
- python - Tkinter 中输入框的条件
- mysql - 如何从 MySql 中的“唯一”字段中插入两条或多条记录?
- vba - winhttp 请求仅在 fiddler 用作代理时有效
- mac-catalyst - 跟踪用户何时返回应用程序或将焦点从 Mac Catalyst 窗口移开
- c# - C# 通过名称触发类中的函数
- java - “/”的 Json toString 输出
- ios - 如何在不使用开关的情况下返回带有参数的枚举值?
- python - 如何为多个点设置动画以围绕单个点独立旋转?
- javascript - 无法让我的 JS 函数(一次播放一个视频)进行滚动捕捉