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, 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 User.new 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 User.new, for e.g: user = User.new. 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: -

User.find(1).update(name:”peter”)

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

Click Here for reading the full blog.

--

--

--

Cryptex specializes in developing open source web applications and software solutions across all domains and verticals using Ruby on Rails (ROR) technology

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

GIT — add some validations before commit

How to create custom shell scripts

Spring Boot Oauth2 Mutual TLS Client — Client Credentials Grant

Best Rust Server Hosting Providers for Gamers

When Choosing A Baby Mattress concerns You ShouldAsk https://t.co/RwqDECYWLK

Code Challenge

Quick Notes on Munki powered by SimpleMDM (…and how this works along Zentral open-source)

RubyConf 2017 Retrospective — Day 3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cryptex Technologies

Cryptex Technologies

Cryptex specializes in developing open source web applications and software solutions across all domains and verticals using Ruby on Rails (ROR) technology

More from Medium

How to use Devise gem with Ruby on Rails 7

Ruby and Ruby on Rails

Monitor your Ruby on Rails App using Signoz + OpenTelemetry

Rspec in brief