(はい、試しましたautosave: true
)
ユーザー、投稿、コメントの 3 つのモデルがあります。コメントは投稿とユーザーに属します。
したがって、Comments#create には次の行があります。
@comment = current_user.comments.build(params[:comment])
post_id は params で として渡されcomment: {post_id: post_id}
ます。ただし、mongoid はオブジェクトを保存するときにそれを完全に無視します。明らかに、のようなものを追加することで解決でき@comment.post = post
ます。それは適切な解決策ですか、それとももっときれいにできますか?