#RAILS (the CLI)
Objectives:
- Understand that a CLI is just like any normal software except it is used through Terminal and does not have a GUI.
- You do not need to memorize commands in order to learn Rails. The manual pages are for that!
###What is a CLI?
A command-line interface or command language interpreter (CLI), also known as command-line user interface, console user interface,[1] and character user interface (CUI), is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines).
###So we "do code" in our CLI?
The answer is pretty much NO!
Here we can run generators, that will create files, that have template code. This is not the same as writing code!
Ok, lets test it out.
Navigate to your test (scratch) directory where we can spin up our first rails app (and then subsequently delete it).
Do:
$ rails -h
Seems like a pretty good place to start. -h
stands for help
On these manual pages (usually accessible through -h
) keep a look out for the "USAGE" section.
In this case :
Usage:
rails new APP_PATH [options]
There is also a list of helpful options.
Basically this is saying if I do rails new appName
it will generate all the files and folders needed to have a rails app named "appName"
#Just Do It
rails new someBadName
cd someBadName
This part is the most commonly forgotten step. Rails generates a new directory from the directory at which you rails new
so you will need cd
into it.
rails -h
notice this time the output is different. This is because rails is recognizing that we are now inside a rails app. This time it will list the five main things that Rails can do for us. (In a GUI these tools might be available under a clickable "file" tab in the menu bar. Dont' be scared of the CLI, its just the same).
Usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
Generate
rails generate -h
There are many generators that we can use. Here is a comprehensive list. As we add certain gems, this might make new generators available.
Console
rails console -h
This is where you can interact with your data using a gem called Active Record (more on that later)
(without the -h
obvs)
Server
rails server -h
This is how you fire up the server for your application.
(without the -h
obvs)