At the end of this lesson you with have a created your first rails project.
- Rails New
- Rails Controllers
- Rails Views
First, let's make sure we are in the correct directory:
cd ~/lessons/ra-102
Next, we'll create a personal branch to work out of named after your Github username:
git checkout -b YOUR_GITHUB_USERNAME
A quick way to get your Github username is to run:
gh api user --jq '.login'
After that you should see a terminal like:
~/lessons/ra-102 (branch: github_username)
$ _
Still in the ra-102
directory, run the following command to create a new Rails project:
rails new . --skip-git
This will create a new Rails project in the current directory, skipping git because the lesson already has a git repository.
Now lets our ruby gems by running:
bundle install
rails server
Visit http://localhost:3000 in your browser to see your new app running with the default Rails welcome page.
git add .
git commit -m "Installed Rails"
rails generate controller home index
This will create a new controller called home
with an action called index
.
Open the config/routes.rb
file and add the following line
root 'home#index'
This will set the home#index
action as the root of the application.
Open the app/views/home/index.html.erb
file and add the following line:
<h1>Hello World</h1>
Start the local server by running:
rails server
If you see "Hello World" on http://localhost:3000 it's working.
git add .
git commit -m "Added home controller"
gh pr create
- Visit your PR on Github.
The automatic check will run if your code passes, you'll see:
✅ All checks have passed
Get your free server in the next lesson.