[英]Override belongs_to has_many foreign key value
I have something set-up with two models. 我有两个模型的设置。
user
and posts
. user
和posts
。 user has_many
posts and posts belongs_to
user. 用户
has_many
职位和belongs_to
用户。 I created a bunch of posts using one admin user
and now I want to assign each post to a different user
. 我使用一个管理员
user
创建了一堆帖子,现在我想将每个帖子分配给另一个user
。 I tried creating a form
for post
and just updating the user_id
field, but I get the message Unpermitted parameter: user_id
and the field will not update - it just reverts back to the original user_id
. 我尝试为
post
创建form
并仅更新user_id
字段,但收到消息Unpermitted parameter: user_id
并且该字段将不会更新-它将恢复为原始的user_id
。
How can I force the form to accept the new user_id
? 如何强制表单接受新的
user_id
?
Just had to add :user_id
to params in the controller. 只需将
:user_id
添加到控制器中的params中即可。 Foolish oversight. 愚蠢的监督。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.