Other Pages

setting_the_default_page.step

goals {
  goal "The main page of our app should be the list of topics."

  message <<-MARKDOWN


  Currently when you go to your server main page,
  you see the Rails Logo and Version. It would be easier to use our app if
  the main page went directly to the topics list.
  In this step we'll make that happen and learn a bit about routes in Rails.
  MARKDOWN
}

steps {

  step do
    message "open `http://localhost:3000/` - it's still the default page"
  end

  step  do
    message "Open the file `config/routes.rb` in the editor."

    message "Look for the line `Rails.application.routes.draw` at the beginning of the file, and add the line `root 'topics#index'` after it. When you are done the start of the file should look like this:"

    source_code :ruby, <<-RUBY
Rails.application.routes.draw do
  root 'topics#index'
    RUBY

  end

  step  do
    message "Check `http://localhost:3000/` again. You should see the topics list now."
  end


  step do
    message "let's look at all the routes created by the scaffold - in the terminal"
    console "rails routes -c topics"
  end
}

explanation {

 message <<-MARKDOWN
  * `root 'topics#index'` is a Rails route that says the default
    address for your site the one given by the topics controller with the index action.
  * Rails routes control how URLs (web addresses) get matched with
    code on the server.
  * The file `config/routes.rb` is like an address book listing the
    possible addresses and which code goes with each one
  * `routes.rb` uses some shortcuts so it doesn't always show all the
    possible URLs. To explore the URLs in more detail we can use the
    terminal.
  * When reading the output of `rails routes`  `:id` means the primary key of a record. `:format` is the
    format of the view, e.g. `html` or `json`.

```
    Prefix Verb   URI Pattern                Controller#Action
      root GET    /                          topics#index
    topics GET    /topics(.:format)          topics#index
           POST   /topics(.:format)          topics#create
 new_topic GET    /topics/new(.:format)      topics#new
edit_topic GET    /topics/:id/edit(.:format) topics#edit
     topic GET    /topics/:id(.:format)      topics#show
           PATCH  /topics/:id(.:format)      topics#update
           PUT    /topics/:id(.:format)      topics#update
           DELETE /topics/:id(.:format)      topics#destroy
```



  MARKDOWN
}

commitnow do
  message "find a good commit message and commit your changes"
end

next_step "voting_on_topics"