Routes Controller View Reference


Premium Content - Free Preview

Rails Server

Enter the following command in your terminal to start your app's server:

rails server 

On cloud9:

rails server -b $IP -p $PORT 

Routes

get 'path', to: 'controller#action'

Here's a standard route that maps /about to the store controller's about action:

get 'about', to: 'store#about'

Root route:

root to: 'store#home'

Multiple standard routes can be created in one line:

resources :products

git and Heroku

Add files to git

  • git add . - Adds everything to git.
  • git commit -m "message about feature" - Commits your changes to git.

Heroku

  • 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.

Controller

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

View

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.


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Contact Us
Sign in or email us at [email protected]