Rails 5:rails s与bundle exec rails s

时间:2016-10-11 20:39:46

标签: ruby-on-rails bundler ruby-on-rails-5

我第一次在Rails 5上开始了一个项目,我很好奇为什么在Rails 4上运行'rails s'工作正常,但是现在我在Rails 5上我需要用它来预备它'bundle exec'以便正确运行命令。

下面是我的Gemfile。如果我在我的所有rails命令前面加上,那么一切正常。我只是好奇是否有其他人遇到这种情况,或者有人可以给我一些关于为什么会发生这种情况的见解?

 source 'https://rubygems.org'
 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
 # Use postgresql as the database for Active Record
 gem 'pg', '~> 0.18'
 # Use Puma as the app server
 gem 'puma', '~> 3.0'
 # Use SCSS for stylesheets
 gem 'sass-rails', '~> 5.0'
 # Use Uglifier as compressor for JavaScript assets
 gem 'uglifier', '>= 1.3.0'
 # Use CoffeeScript for .coffee assets and views
 gem 'coffee-rails', '~> 4.2'
 # See https://github.com/rails/execjs#readme for more supported runtimes
 # gem 'therubyracer', platforms: :ruby

 # Use jquery as the JavaScript library
 gem 'jquery-rails'
 # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
 gem 'turbolinks', '~> 5'
 # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
 gem 'jbuilder', '~> 2.5'
 # Use Redis adapter to run Action Cable in production
 # gem 'redis', '~> 3.0'
 # Use ActiveModel has_secure_password
 # gem 'bcrypt', '~> 3.1.7'

 gem 'bootstrap', '~> 4.0.0.alpha3'
 source 'https://rails-assets.org' do
 gem 'rails-assets-tether', '>= 1.1.0'
 end
 gem "paperclip", "~> 5.0.0"
 gem "browser"
 # Use Capistrano for deployment
 gem 'capistrano-rails', group: :development

 group :development, :test do
 # Call 'byebug' anywhere in the code to stop execution and get a debugger console
 gem 'byebug', platform: :mri
 end

 group :development do
 # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
 gem 'web-console'
 gem 'listen', '~> 3.0.5'
   # Spring speeds up development by keeping your application running in the  background. Read more: https://github.com/rails/spring
   gem 'spring'
   gem 'spring-watcher-listen', '~> 2.0.0'
 end

 # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

2 个答案:

答案 0 :(得分:2)

听起来你在全球范围内安装的rails命令是轨道4,这就是原因&#34;它没有正确运行&#34;就像你说的。当您运行bundle exec时,它会使用当前rails中的Gemfile命令,因为您的Gemfile中有rails 5,然后它才能正常运行。

我建议使用RVMrbenv,我个人喜欢RVM,因为它会自动切换到我的Gemfile中指定的ruby版本的gemset。

例如,当我cd进入项目目录时,我收到如下消息:

  

RVM使用你的Gemfile来选择Ruby,一切都很好 - Heroku也是这样做的。

答案 1 :(得分:1)

使用bundle exec保证程序与gemfile中指定的环境一起运行,这有望意味着它是程序创建者希望它运行的环境,这有望意味着它应该正确运行,无论什么您计算机上的奇怪设置。

参考:Use bundle exec rake or just rake?