[Rails] How to write user_id (foreign key) in strong parameter

Posted content

This time, the output is how to describe the foreign key in the strong parameter.

Implementation method

controller.rb


private

def item_params
  params.require(:item).permit(:name, :description, :category, :brand, :condition, :shipping_cost, :prefecture_id, :shipping_day, :price, images_attributes: [:image]).merge(user_id: current_user.id)
end

Described using the merge method like this. In this case, the id of the logged-in user is saved in the parameter as user_id`.

Finally

This time the output is concise! Please refer to!

Recommended Posts

[Rails] How to write user_id (foreign key) in strong parameter
[Rails] How to write in Japanese
How to write Rails
How to write Rails validation
How to write Rails seed
How to write Rails routing
How to write a date comparison search in Rails
How to write an external reference key in FactoryBot
Rails on Tiles (how to write)
How to introduce jQuery in Rails 6
[Rails5] japanMap link How to write parameters in js.erb file
How to install Swiper in Rails
How to write the view when Vue is introduced in Rails?
How to implement search functionality in Rails
How to change app name in rails
How to insert a video in Rails
How to use MySQL in Rails tutorial
How to implement ranking functionality in Rails
How to delete data with foreign key
How to use credentials.yml.enc introduced in Rails 5.2
Rails: How to write a rake task nicely
[Ruby] Basic key to be strong in refactoring
[JavaFX] How to write Eclipse permissions in build.gradle
[Rails] How to write when making a subquery
[Rails] How to use select boxes in Ransack
How to translate Rails into Japanese in general
How to prevent direct URL typing in Rails
How to conditionally add html.erb class in Rails
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to use JQuery in js.erb of Rails6
[Ruby on Rails] How to install Bootstrap in Rails
How to make a follow function in Rails
How to write Java String # getBytes in Kotlin?
[Rails] How to use PostgreSQL in Vagrant environment
How to check Rails commands in the terminal
Notes on how to write comments in English
How to uninstall Rails
How to write Mockito
How to write migrationfile
How to set the display time to Japan time in Rails
How to implement guest login in 5 minutes in rails portfolio
[Ruby On Rails] How to reset DB in Heroku
[How to insert a video in haml with Rails]
How to query Array in jsonb with Rails + postgres
[Rails 6] How to set a background image in Rails [CSS]
[Rails] How to get the contents of strong parameters
[Rails] How to load JavaScript in a specific view
[Rails] How to display an image in the view
How do you create foreign key values ​​in FactoryBot ~ (crying
[rails] How to post images
How to write good code
[Rails] How to use enum
How to write a migration from Rails datetime type to date type
How to use a foreign key with FactoryBot ~ Another solution
Bit Tetris (how to write)
[Rails] How to install devise
[Rails] How to use enum
How to write java comments
How to read rails routes
[Refactoring] How to write routing