Rails 4: Insert Attribute Into Params

前端 未结 4 539
忘了有多久
忘了有多久 2020-12-12 18:36

In Rails 3, it was possible to insert an attribute into params like so:

params[:post][:user_id] = current_user.id

I\'m attempting to do som

4条回答
  •  一向
    一向 (楼主)
    2020-12-12 19:38

    As an alternative for this case, you can required pass attribute via scope:

    current_user.posts.create(post_params)

提交回复
热议问题