Gorigori beginners summarized how to operate the database using rails console Ntiunus

This time, I will briefly summarize how to operate the database using rails console.

① Add data to the table.

  $rails console
  ///Below, in the command Post.In the content column with new"Hello World"Will be added.
  post = Post.new(content:"Hello World")

② Save the post.

  $rails console
  post = Post.new(content:"Hello World")
  ///Below, save the post with the command.
  post.save

③ Get the data and refer to it.

  $rails console
  post = Post.new(content:"Hello World")
  post.save
  ///Hereafter, the data is acquired.
  post = Post.first
  ///Visually confirm that the acquired data matches the data stored in the database.
  post.content

It's too simple to understand, but I'll improve the accuracy of the explanation in the future. .. Lol

Recommended Posts

Gorigori beginners summarized how to operate the database using rails console Ntiunus
[Rails] How to display information stored in the database in view
[Rails] How to reset the database in production environment (Capistrano version)
[Rails 5] How to display the password change screen when using devise
[Rails] How to use rails console with docker
[Rails] How to use the map method
How to implement image posting using rails
Summarized how to climb the programming stairs
[Rails] How to handle data using enum
How to build a Ruby on Rails environment using Docker (for Docker beginners)
How to debug the processing in the Ruby on Rails model only on the console
[Ruby On Rails] How to search the contents of params using include?
[Rails] How to decide the destination by "rails routes"
[Rails] How to create a graph using lazy_high_charts
How to implement the breadcrumb function using gretel
[For beginners] How to implement the delete function
How to delete the database when recreating the application
[Rails] How to upload multiple images using Carrierwave
[Rails] How to operate the helper method used in the main application with Administrate
[Java] How to operate List using Stream API
How to check Rails commands in the terminal
[Rails / Uniqueness constraint] How to check model validation on the console / Uniqueness constraint for multiple columns
[Rails] How to solve the error "undefined method` visit'" when using Capybara with Rspec
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
How to remove the underline displayed by Rails link_to
[Ruby on Rails] How to change the column name
[For beginners] How to operate Stream API after Java 8
[Rails] I don't know how to use the model ...
[Rails] How to change the column name of the table
[Rails] How to get the contents of strong parameters
Rails learning How to implement search function using ActiveModel
[Rails] How to display an image in the view
[Rails] How to install a decorator using gem draper
How to write Rails
How to uninstall Rails
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
Add an icon to the header link using Rails fontawesome
Prevent operations! How to securely update Rails manually using transactions
[With back tricks] How to introduce React to the simplest Rails
I have summarized the articles that programming beginners referred to.
How to set and describe environment variables using Rails zsh
How to deploy jQuery in your Rails app using Webpacker
[Rails] How to delete images uploaded by carrierwave (using devise)
Let's summarize how to extend the expiration date of Rails
How to install JDK 8 on Windows without using the installer
[Rails] How to display the list of posts by category
How to run React and Rails on the same server
How to play MIDI files using the Java Sound API
[Docker] How to forcibly disconnect the session connected to the database [Postgres]
[Rails] How to display error messages for comment function (for beginners)
How to check the database of apps deployed on Heroku
[Rails] How to convert the URI of the image sent by http to https when using Twitter API
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
How to use rails join
How to terminate rails server
How to write Rails validation