因为初学Ruby,四处查资料无果,才来的贴出亲自试过的操作,覆盖整个个人入门笔记博客中,故所有的操作,都以最明了的方式阐述,当你创建完一个新的Rails应用后,你发现JAVA中我们可以编写maven聚合项目来控制其子项目的JDK,TOMCAT等等的版本,那么Ruby是怎样来管理的呢,答案就是在Gemfile中加依赖,而这个文件不是你手动编写的,而是使用Bundler来安装和引入该应用所需的gem。执行rails new命令时会自动运行Bundler(bundle install命令),而bundle就是根据Gemfile文件中的来依赖你所定义的源,就像JAVA中的依赖jar包一样。下面先看看默认生成的Gemfile中有什么?
1 source 'https://rubygems.org' 2 git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4 ruby '2.3.1' 5 6 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7 gem 'rails', '~> 5.2.0' 8 # Use sqlite3 as the database for Active Record 9 gem 'sqlite3' 10 # Use Puma as the app server 11 gem 'puma', '~> 3.11' 12 # Use SCSS for stylesheets 13 gem 'sass-rails', '~> 5.0' 14 # Use Uglifier as compressor for JavaScript assets 15 gem 'uglifier', '>= 1.3.0' 16 # See https://github.com/rails/execjs#readme for more supported runtimes 17 # gem 'mini_racer', platforms: :ruby 18 19 # Use CoffeeScript for .coffee assets and views 20 gem 'coffee-rails', '~> 4.2' 21 # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22 gem 'turbolinks', '~> 5' 23 # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24 gem 'jbuilder', '~> 2.5' 25 # Use Redis adapter to run Action Cable in production 26 # gem 'redis', '~> 4.0' 27 # Use ActiveModel has_secure_password 28 # gem 'bcrypt', '~> 3.1.7' 29 30 # Use ActiveStorage variant 31 # gem 'mini_magick', '~> 4.8' 32 33 # Use Capistrano for deployment 34 # gem 'capistrano-rails', group: :development 35 36 # Reduces boot times through caching; required in config/boot.rb 37 gem 'bootsnap', '>= 1.1.0', require: false 38 39 group :development, :test do 40 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42 end 43 44 group :development do 45 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51 end 52 53 group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15', '< 4.0' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59 end 60 61 # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 62 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]