How To Use Rails Console In Application

How To Use Rails Console In Application

01 Oct 2022
How To Use Rails Console In Application

Rails console is an IRB session built into the rails environment and can be operated by typing “rails c” in the terminal. It can be utilized to test connection methods, and validations and check error messages while building a Rails application.

To start the rails console, run the following command run on the terminal.

$ rails console

Create a user, using the command. For efficiency and ease of convenience, use a variable to store the data of the new user. Create a new user variable and assign it to the, for e.g: user = The return value will be the user with no attributes i.e

user_id = nil,

name =nil.

This is another way to verify if the attributes of the columns in the database are accurate.

A more agile way to create and save a new user to the database is to apply the method: — create as follows:

user = User.create(name: ‘mark’,address:’America’).

This method creates and saves the object to the database.

Similarly, the user can update the database entry by using the command: -


With this command, the entry can be easily updated by passing the id.

Click Here for reading the full blog.

Leave a comment: