Sarp Kaya
Sarp Kaya

Reputation: 3794

Rails how to use console

I am a rookie in Rails. My ultimate goal is to add a user in devise (I know it's not a good practise but I only need to do it once). I've seen that you can run commands at the runtime in Rails for Zombies tutorial. (http://railsforzombies.org/levels/1/challenges/1)

This is basically what I want to do. I am using RubyMine and I run the rails application by either running the application or using rails s. However whatever I type is not executed as I do not get any error or any print outs.

So my question is how can I actually execute a command in the console for Rails app?

Upvotes: 1

Views: 421

Answers (3)

Amr Arafat
Amr Arafat

Reputation: 489

rails c

And you can also use:

rails c -s

"-s" stands for sandbox so you can play around without breaking anything. Operations will be automatically reverted when you leave the console.

You can then write:

user = User.new

Upvotes: 1

pangpang
pangpang

Reputation: 8831

rails console: The console command lets you interact with your Rails application from the command line.

You can also use the alias "c" to invoke the console: rails c.

Upvotes: 0

Mandeep
Mandeep

Reputation: 9173

Open terminal -> Go in your app directory by cd command -> type "rails console" or "rails c" -> write your code

To add a new user you can do:

User.create(name: "user_name", email: "user_email", password: "your_password")

Also you should checkout Rails command line

Upvotes: 1

Related Questions