go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Traffic flow
 
Subject: Traffic flow
Author: Linux
In response to: Step 2 -- Create a controller
Posted on: 09/12/2017 01:30:11 AM



                         /config/routes.rb     app/controllers/welcome_controller.rb    
http://localhost:3000/ -------------------->  ----------------------------------------> 
                                ^                     ^   
                                |                     |
                         root 'welcome#index'    def index
                                                  // default to view --> app/views/welcome/index.html.erb
                                                 end




 

> On 09/12/2017 01:16:04 AM Linux wrote:

-- administrator@ubuntu:$ cd blog

-- administrator@ubuntu:~/blog$ rails generate controller Welcome index
Running via Spring preloader in process 69075
      create  app/controllers/welcome_controller.rb
       route  get 'welcome/index'
      invoke  erb
      create    app/views/welcome
      create    app/views/welcome/index.html.erb
      invoke  test_unit
      create    test/controllers/welcome_controller_test.rb
      invoke  helper
      create    app/helpers/welcome_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/welcome.coffee
      invoke    scss
      create      app/assets/stylesheets/welcome.scss


This generated:
  • app/controllers/welcome_controller.rb -- a controller Welcome with action index
    class WelcomeController < ApplicationController
      def index
      end
    end
    


  • app/views/welcome/index.html.erb -- a view associated with controller Welcome and its action index
    <h1>Welcome#index</h1>
    <p>Find me in app/views/welcome/index.html.erb</p>
    


  • a routing instruction added into routing table config/routes.rb
    Rails.application.routes.draw do
      get 'welcome/index'
      # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
    end
    

    Here, get 'welcome/index' maps the GET request http://<host>/welcome/index(or index.html) to controller welcome and action index.

    The root request http://<host>/ is routed to the default "Rails Welcome Aboard!" page. If you want to map the root request to controller welcome and action index. You can add root 'welcome#index':
    Rails.application.routes.draw do
      get 'welcome/index'
      root 'welcome#index'  
      # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
    end
    






    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.