简体   繁体   English

覆盖belongs_to has_many外键值

[英]Override belongs_to has_many foreign key value

I have something set-up with two models. 我有两个模型的设置。 user and posts . userposts 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM