Routes Controller View Reference
Premium Content - Free Preview
Enter the following command in your terminal to start your app's server:
rails server -b $IP -p $PORT
get 'path', to: 'controller#action'
Here's a standard route that maps
/about to the store controller's
get 'about', to: 'store#about'
root to: 'store#home'
Multiple standard routes can be created in one line:
git and Heroku
Add files to git
git add .- Adds everything to git.
git commit -m "message about feature"- Commits your changes to git.
git push heroku master- pushed your updated code to Heroku.
heroku run rake db:migrate- runs database migrations on your Heroku site.
heroku run console- run the Rails console on your Heroku app.
A controller controls access to an application and makes data available to the view.
rails g controller Store home - generates a Store controller with a
home action and associated files.
class StoreController < ApplicationController def home @title = "Automated Store" end end
@title is now available for the view file to use (home.html.erb).
Usually, the controller makes data from the model available to the view. For example:
def index @products = Product.all end
The view folders consist of html.erb page templates that are processed and sent to the user. Each template can contain Ruby code to display data from the controller.