Skip to content
This repository
Browse code

Merge pull request #6491 from rafmagana/getting_started_update_settin…

…g_app_home_page

[getting started] Update Setting the Application Home Page to show the generated get "welcome/index" route
  • Loading branch information...
commit 4b911835e3572c927320c0de9911ffbddd7be23f 2 parents 1ca3133 + 12111e2
Vijay Dev vijaydev authored

Showing 1 changed file with 36 additions and 6 deletions. Show diff stats Hide diff stats

  1. +36 6 guides/source/getting_started.textile
42 guides/source/getting_started.textile
Source Rendered
@@ -177,7 +177,28 @@ To create a new controller, you will need to run the "controller" generator and
177 177 $ rails generate controller welcome index
178 178 </shell>
179 179
180   -Rails will create several files for you. Most important of these are of course the controller, located at +app/controllers/welcome_controller.rb+ and the view, located at +app/views/welcome/index.html.erb+.
  180 +Rails will create several files and a route for you.
  181 +
  182 +<shell>
  183 +create app/controllers/welcome_controller.rb
  184 + route get "welcome/index"
  185 +invoke erb
  186 +create app/views/welcome
  187 +create app/views/welcome/index.html.erb
  188 +invoke test_unit
  189 +create test/functional/welcome_controller_test.rb
  190 +invoke helper
  191 +create app/helpers/welcome_helper.rb
  192 +invoke test_unit
  193 +create test/unit/helpers/welcome_helper_test.rb
  194 +invoke assets
  195 +invoke coffee
  196 +create app/assets/javascripts/welcome.js.coffee
  197 +invoke scss
  198 +create app/assets/stylesheets/welcome.css.scss
  199 +</shell>
  200 +
  201 +Most important of these are of course the controller, located at +app/controllers/welcome_controller.rb+ and the view, located at +app/views/welcome/index.html.erb+.
181 202
182 203 Open the +app/views/welcome/index.html.erb+ file in your text editor and edit it to contain a single line of code:
183 204
@@ -195,18 +216,27 @@ You need to do this because Rails will serve any static file in the +public+ dir
195 216
196 217 Next, you have to tell Rails where your actual home page is located.
197 218
198   -Open the file +config/routes.rb+ in your editor. This is your application's _routing file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. Find the line beginning with +root :to+ and uncomment it. It should look something like the following:
  219 +Open the file +config/routes.rb+ in your editor.
199 220
200 221 <ruby>
201 222 Blog::Application.routes.draw do
202   -
203   - #...
  223 + get "welcome/index"
  224 +
  225 + # The priority is based upon order of creation:
  226 + # first created -> highest priority.
  227 + # ...
204 228 # You can have the root of your site routed with "root"
205 229 # just remember to delete public/index.html.
206   - root :to => "welcome#index"
  230 + # root :to => "welcome#index"
  231 +</ruby>
  232 +
  233 +This is your application's _routing file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. Find the line beginning with +root :to+ and uncomment it. It should look something like the following:
  234 +
  235 +<ruby>
  236 +root :to => "welcome#index"
207 237 </ruby>
208 238
209   -The +root :to => "welcome#index"+ tells Rails to map requests to the root of the application to the welcome controller's index action. This was created earlier when you ran the controller generator (+rails generate controller welcome index+).
  239 +The +root :to => "welcome#index"+ tells Rails to map requests to the root of the application to the welcome controller's index action and +get "welcome/index"+ tells Rails to map requests to "http://localhost:3000/welcome/index":http://localhost:3000/welcome/index to the welcome controller's index action. This was created earlier when you ran the controller generator (+rails generate controller welcome index+).
210 240
211 241 If you navigate to "http://localhost:3000":http://localhost:3000 in your browser, you'll see the +Hello, Rails!+ message you put into +app/views/welcome/index.html.erb+, indicating that this new route is indeed going to +WelcomeController+'s +index+ action and is rendering the view correctly.
212 242

0 comments on commit 4b91183

Please sign in to comment.
Something went wrong with that request. Please try again.