Ruby On Rails getting started (installation and use process)

Source: Internet
Author: User

I have the opportunity to try Rails again, but I only came into contact with 2 and now it has become 4. It seems that the current installation is faster than the original one ..

Rails 4 installation

For RVM Installation
Copy codeThe Code is as follows: gem install rails
Otherwise, it should be as follows:
Copy codeThe Code is as follows: sudo gem install rails
Instructions for installing RVM
Copy codeThe Code is as follows: curl-L https://get.rvm.io | bash-s stable

View the rails version

Copy codeThe Code is as follows: rails-v
Rails 4.0.3
It seems that this is the latest version.

Ruby version

Copy codeThe Code is as follows: We recommend Ruby 2.1.0 for use with Rails. We stopped supporting Ruby 1.8.x after Rails 3.2. Ruby 1.9.2 + will be supported until Rails 5.

2.1.0 is officially recommended, which is the latest version.

Install SQLite

It seems that this is the database Requirements for lightweight websites such as Django and Rails.

For mac OS

Copy codeThe Code is as follows: brew install sqlite3
Other installation methods, such as openSUSE
Copy codeThe Code is as follows: sudo zypper install sqlite3


Rails 4 Hello, World

You can use rails to generate
Copy codeThe Code is as follows: $ rails new hello
So there is
Copy codeThe Code is as follows:
Create
Create README. rdoc
Create Rakefile
Create config.ru
Create. 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
The installation package dependency
Copy codeThe Code is as follows:
Fetching gem metadata from https://rubygems.org /..........
Fetching additional metadata from https://rubygems.org /..
Resolving dependencies...
Using rake (10.3.1)
Using i18n (0.6.9)
Using minitest (4.7.5)
Using multi_json (1.9.2)
Using thread_safe (0.3.3)
Using tzinfo (0.3.39)
Using activesupport (4.0.3)
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.3)
Using mime-types (1.25.1)
Using polyglot (0.3.4)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.3)
Using activemodel (4.0.3)
The Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.2)
Using activerecord (4.0.3)
Using bundler (1.5.3)
Using coffee-script-source (1.7.0)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using thor (0.19.1)
Using railties (4.0.3)
Using coffee-rails (4.0.1)
Using hike (1.2.3)
Using jbuilder (1.5.3)
Using jquery-rails (3.1.0)
Using json (1.8.1)
Using tilt (1.4.1)
Using sprockets (2.11.0)
Using sprockets-rails (2.0.1)
Using rails (4.0.3)
Using rdoc (4.1.1)
Using sass (3.2.19)
Using sass-rails (4.0.3)
Using sdoc (0.4.0)
Using sqlite3 (1.3.9)
Using turbolinks (2.2.2)
Using uglifier (2.5.0)
Your bundle is complete!
Use 'bundle show [gemname] 'to see where a bundled gem is installed.

Run Rails

Copy codeThe Code is as follows: $ rails server
In this case, open http: // localhost: 3000 and you will be able to see that the Welcome page of Rails is Welcome aboard, which is a bit similar to Django-CMS's pony ~~

Create a controller

As the official guide says http://guides.rubyonrails.org/getting_started.html

Run the following command:
Copy codeThe Code is as follows: $ rails generate controller welcome index
The following files will be created:
Copy codeThe Code is as follows:
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

Add default page in config/routes. rb
Copy codeThe Code is as follows: root 'Welcome # Index'
Run again
Copy codeThe Code is as follows: rails server
It will appear

Copy codeThe Code is as follows: Welcome # index

Find me in app/views/welcome/index.html. erb


Everything came fast and suddenly.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.