Other Pages

create_a_rails_app.step

tip do
console_with_message "From here on, this guide assumes you have Rails 5.0.x. To check your Rails version, type this in the terminal:", "rails -v"
fuzzy_result "Rails 5.0{FUZZY}.x{/FUZZY}"
message "If your computer reports a Rails version less than 5.0, ask a TA help get you back on track."
end
step "Change to your home directory" do
insert 'switch_to_home_directory'
end
step "Create a railsbridge directory" do
console "mkdir railsbridge"
message "`mkdir` stands for make directory (folder)."
message "We've made a folder called `railsbridge`."
end
step "Change to your new railsbridge directory" do
console "cd railsbridge"
end
step "Create a new Rails app" do
console "rails new test_app"
message "The command's output is voluminous, and will take some time to complete, with a long pause in the middle, after all the 'create...' statements ending in 'bundle install'. When it fully completes, it will return you to your home prompt. Look for the 'Bundle complete!' message just above."
console "cd test_app"
console "rails server"
tip "In OS X, you may need to let Ruby accept incoming network connections through your firewall. Select 'allow' in the pop up."
tip "In Windows, you may need to let Ruby and Rails communicate through your firewall. Say yes to the pop up."
tip "Shortcut: Just type 'rails s'" do
message <<-MARKDOWN
Throughout your Rails programming career you're going to type `rails server` a
lot. Simply typing `rails s` is the same as `rails server`.
MARKDOWN
end
message <<-MARKDOWN
The first command should produce no output.
If `rails server` starts up with no errors, you're golden! It'll look something like this:
MARKDOWN
fuzzy_result <<-TEXT
=> Booting Puma
=> Rails 5.0{FUZZY}.0{/FUZZY} application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version {FUZZY}3.4.0{/FUZZY} (ruby 2.{FUZZY}2.2-p95{/FUZZY}), codename: {FUZZY}Owl Bowl Brawl{/FUZZY}
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
TEXT
message "If it does, congratulations! You've successfully installed Ruby AND Rails and started your server."
tip "If it doesn't work, ask a TA for help."
message "* In your browser, go to <http://localhost:3000>"
img src: "img/successful_rails_install.png", alt: "Screenshot of the browser on localhost 3000 showing the rails intro page"
message <<-MARKDOWN
* Back in the Terminal window where you ran <code>rails server</code>, type **Control-C** (don't type this into the console, but hold the Control and C keys at the same time) to kill(stop) the server. Windows will ask "Terminate batch job (Y/N)?". Type "Y".
MARKDOWN
important "On Windows, sometimes Control-C doesn't work. In that case, look for the key called 'Break' or 'Pause' and press Control-Break, then answer Y at the prompt. If there is no Pause/Break key on your keyboard, you can run `ruby script/rails server` instead of `rails server` which should allow Control-C to stop the server."
end
step "Generate a database model" do
tip "If your prompt doesn't already show that you are (still) in the test_app folder" do
console "cd test_app"
end
console <<-BASH
rails generate scaffold drink name:string temperature:integer
BASH
console <<-BASH
rails db:migrate
BASH
console <<-BASH
rails server
BASH
message <<-MARKDOWN
**Note:** the above are three separate commands. Type each line into the terminal separately, not as one single command.
Wait until your console shows that the Puma server has started (just like before). Then, in the browser, visit <http://localhost:3000/drinks>
1. Click on "New drink"
2. Enter Cappuccino for the name
3. Enter 135 for the temperature.
4. Click on "Create Drink".
(The window where you ran `rails server` will display debugging information as you do this.)
You should see: ![Screenshot of the drink detail page](img/get_a_sticker_you_should_see.png)
In your terminal, Hold Control and hit C (or on Windows, Control-Break, Y) to stop the rails server.
MARKDOWN
end
next_step "deploy_a_rails_app"

Going through this curriculum on your own? Get help on our Discourse forum, where RailsBridge volunteers can answer your questions.

If you have a suggestion for improving the docs, please make a pull request or drop us a note via GitHub Issues (no technical knowledge required).