Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Launching Rails console1:04 with Jay McGavren
We've seen how to use the Web interface to create new model objects. Now, I want to show you how to do the same from the terminal, using the "Rails console".
To launch the Rails console, type in your terminal:
You'll leave your system prompt, and be taken to a prompt provided by Ruby. Here you can type Ruby expressions. They'll be evaluated, and you'll be shown the result.
We've seen how to use the web interface to create new model objects.
Now I wanna show you how to do the same from the terminal using the Rails console.
The Rails console is useful when you need to do an operation on many model objects
at once, or to look at model attributes that you haven't yet added to your views.
We've seen the Rails server and generate sub commands already.
Console is another sub command.
So let's make sure the Rails server is stopped and
we're back at our system prompt.
Then we type bin/ rails console in our terminal.
You'll leave your system prompt and be taken to a prompt provided by Ruby.
Here you can type Ruby expressions.
They'll be evaluated and you'll be shown the result.
If you've used Ruby's IRB command before, it works just the same way.
The difference is you have your full Rails environment loaded,
including your model classes.
Your model class is connected to your database so
you can create, read, update, or delete model data.
Let's try out all the cred operations using our post model class.
You need to sign up for Treehouse in order to download course files.Sign up