Creating your First Rails (Ruby on Rails) Application

Get your Rails installed and configured fine.  Refer to: Step-by-Step procedure: Installing Rails (Ruby on Rails) on Windows 7 x64 bit system 

 

Creating and running your first Rails application and accessing it via browser:

  1. Before getting on with Rails development, you need to make sure you have appropriate version of SQLite3 gem installed on your system. You can install it using command: gem install sqlite3 from Command prompt with Ruby.
  2. Create a Folder to put your Rails project files, say “C:RailApps”, the CD to that folder.
  3. Then Open Command Prompt, verify your Rails Version by using command: rails –v
  4. Then create a new application using command: rails new <appname>image
  5. Then CD to the newly created subfolder
  6. Then Start the rails Server by running the command: rails server

    C:RailAppsDialogExpress>rails server
    => Booting WEBrick
    => Rails 4.0.2 application starting in development on http://0.0.0.0:3000
    => Run `rails server -h` for more startup options
    => Ctrl-C to shutdown server
    [2013-12-13 12:55:05] INFO  WEBrick 1.3.1
    [2013-12-13 12:55:05] INFO  ruby 2.0.0 (2013-11-22) [x64-mingw32]
    [2013-12-13 12:55:05] INFO  WEBrick::HTTPServer#start: pid=8832 port=3000 image

  7. Then access the Rails application web site via: http://localhost:3000/ imageimage
  8. Then use Ctrl + C to stop the server:

    Started GET "/rails/info/properties" for 127.0.0.1 at 2013-12-13 12:55:45 +0530
    Processing by Rails::InfoController#properties as */*
      Rendered C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/templates/rails/info/properties.html.erb (0.0ms)
    Completed 200 OK in 55ms (Views: 34.0ms | ActiveRecord: 13.0ms)
    [2013-12-13 13:01:29] INFO  going to shutdown …
    [2013-12-13 13:01:29] INFO  WEBrick::HTTPServer#start done.
    Exiting
    Terminate batch job (Y/N)? Y

    C:RailAppsDialogExpress>

  9. Generate a Controller and View for your application using below command:                 rails generate controller welcome index
  10. C:>cd RailAppsDialogExpress

    C:RailAppsDialogExpress>rails generate controller welcome index
          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
          create      test/helpers/welcome_helper_test.rb
          invoke  assets
          invoke    coffee
          create      app/assets/javascripts/welcome.js.coffee
          invoke    scss
          create      app/assets/stylesheets/welcome.css.scss

    C:RailAppsDialogExpress>image

  11. Modify the Contents of the View file: appviewswelcomeindex.html.erb.  This is the file that going to be your website startup and/or load page.  From:image  To: image 
  12. Now you need to tall the Rails server to load the modified index.html.erb as your websites home page by editing routes.rb file as shown below: add line: root ‘welcome#index’ image
  13. Now go ahead and load your web site by using http://localhost:3000/ and/or http://localhost:3000/welcome/index.html pages and they will appear as image
  14. f
  15. g

 

 

References:

Getting Started with Rails

 

 

 

 

 

C:RailApps>rails new DialogExpress
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create&
#160; .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.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/backtrace_silencers.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.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/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.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  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install
Fetching gem metadata from
https://rubygems.org/……….
Fetching gem metadata from
https://rubygems.org/..
Resolving dependencies…
Installing rake (10.1.0)
Using i18n (0.6.9)
Installing minitest (4.7.5)
Using multi_json (1.8.2)
Using atomic (1.1.14)
Using thread_safe (0.1.3)
Using tzinfo (0.3.38)
Using activesupport (4.0.2)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.2)
Using mime-types (1.25.1)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.2)
Using activemodel (4.0.2)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.1)
Using activerecord (4.0.2)
Using bundler (1.3.5)
Installing coffee-script-source (1.6.3)
Installing execjs (2.0.2)
Installing coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.2)
Installing coffee-rails (4.0.1)
Using hike (1.2.3)
Installing jbuilder (1.5.3)
Installing jquery-rails (3.0.4)
Installing json (1.8.1)
Using tilt (1.4.1)
Using sprockets (2.10.1)
Using sprockets-rails (2.0.1)
Using rails (4.0.2)
Installing rdoc (3.12.2)
Installing sass (3.2.12)
Installing sass-rails (4.0.1)
Installing sdoc (0.3.20)
Installing turbolinks (2.0.0)
Installing uglifier (2.3.2)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data –install
= 1.9.1 : gem install rdoc-data;
rdoc-data –install
>= 1.9.2 : nothing to do! Yay!

C:RailApps>

Leave a Reply

Your email address will not be published. Required fields are marked *