go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Step 2 -- Create a controller
 
Subject: Step 2 -- Create a controller
Author: Linux
In response to: Step 1 -- Create a Rails project container
Posted on: 09/12/2017 01:16:04 AM

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



     

    > On 09/11/2017 05:53:03 AM Linux wrote:

    -- administrator@ubuntu:~$ rails new blog
          create  
          create  README.md
          create  Rakefile
          create  config.ru
          create  .gitignore
          create  Gemfile
             run  git init from "."
    Initialized empty Git repository in /home/administrator/blog/.git/
          create  app
          create  app/assets/config/manifest.js
          create  app/assets/javascripts/application.js
          create  app/assets/javascripts/cable.js
          create  app/assets/stylesheets/application.css
          create  app/channels/application_cable/channel.rb
          create  app/channels/application_cable/connection.rb
          create  app/controllers/application_controller.rb
          create  app/helpers/application_helper.rb
          create  app/jobs/application_job.rb
          create  app/mailers/application_mailer.rb
          create  app/models/application_record.rb
          create  app/views/layouts/application.html.erb
          create  app/views/layouts/mailer.html.erb
          create  app/views/layouts/mailer.text.erb
          create  app/assets/images/.keep
          create  app/assets/javascripts/channels
          create  app/assets/javascripts/channels/.keep
          create  app/controllers/concerns/.keep
          create  app/models/concerns/.keep
          create  bin
          create  bin/bundle
          create  bin/rails
          create  bin/rake
          create  bin/setup
          create  bin/update
          create  bin/yarn
          create  config
          create  config/routes.rb
          create  config/application.rb
          create  config/environment.rb
          create  config/secrets.yml
          create  config/cable.yml
          create  config/puma.rb
          create  config/spring.rb
          create  config/environments
          create  config/environments/development.rb
          create  config/environments/production.rb
          create  config/environments/test.rb
          create  config/initializers
          create  config/initializers/application_controller_renderer.rb
          create  config/initializers/assets.rb
          create  config/initializers/backtrace_silencers.rb
          create  config/initializers/cookies_serializer.rb
          create  config/initializers/cors.rb
          create  config/initializers/filter_parameter_logging.rb
          create  config/initializers/inflections.rb
          create  config/initializers/mime_types.rb
          create  config/initializers/new_framework_defaults_5_1.rb
          create  config/initializers/wrap_parameters.rb
          create  config/locales
          create  config/locales/en.yml
          create  config/boot.rb
          create  config/database.yml
          create  db
          create  db/seeds.rb
          create  lib
          create  lib/tasks
          create  lib/tasks/.keep
          create  lib/assets
          create  lib/assets/.keep
          create  log
          create  log/.keep
          create  public
          create  public/404.html
          create  public/422.html
          create  public/500.html
          create  public/apple-touch-icon-precomposed.png
          create  public/apple-touch-icon.png
          create  public/favicon.ico
          create  public/robots.txt
          create  test/fixtures
          create  test/fixtures/.keep
          create  test/fixtures/files
          create  test/fixtures/files/.keep
          create  test/controllers
          create  test/controllers/.keep
          create  test/mailers
          create  test/mailers/.keep
          create  test/models
          create  test/models/.keep
          create  test/helpers
          create  test/helpers/.keep
          create  test/integration
          create  test/integration/.keep
          create  test/test_helper.rb
          create  test/system
          create  test/system/.keep
          create  test/application_system_test_case.rb
          create  tmp
          create  tmp/.keep
          create  tmp/cache
          create  tmp/cache/assets
          create  vendor
          create  vendor/.keep
          create  package.json
          remove  config/initializers/cors.rb
          remove  config/initializers/new_framework_defaults_5_1.rb
             run  bundle install
    


    This will create a Rails application called blog in a blog directory with all necessary folders and files generated.

    Among them, the most important ones are:
    config -- the directory with configuration files, e.g. routes.rb
    app/controllers -- the directory holding controllers
    app/models -- the directory holding models
    app/views -- the directory holding views





    References:

  •  


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