Ruby on rails Rails 5:Rails s与bundle exec Rails s

Ruby on rails Rails 5:Rails s与bundle exec Rails s,ruby-on-rails,bundler,ruby-on-rails-5,Ruby On Rails,Bundler,Ruby On Rails 5,我第一次在Rails 5上启动了一个项目,我很好奇为什么在Rails 4上运行“Rails s”效果很好,但是现在我在Rails 5上,为了正确运行命令,我需要在它前面加上“bundle exec” 下面是我的档案。同样,如果我在所有rails命令前面加上。我只是好奇是否还有其他人经历过这种情况,或者是否有人能告诉我为什么会发生这种情况 source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github

我第一次在Rails 5上启动了一个项目,我很好奇为什么在Rails 4上运行“Rails s”效果很好,但是现在我在Rails 5上,为了正确运行命令,我需要在它前面加上“bundle exec”

下面是我的档案。同样,如果我在所有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]
源代码'https://rubygems.org'
#捆绑边缘Rails:gem'Rails',github'Rails/Rails'
gem'rails','~>5.0.0','>=5.0.0.1'
#使用postgresql作为活动记录的数据库
宝石'pg','~>0.18'
#使用Puma作为应用程序服务器
宝石“彪马”,“~>3.0”
#将SCS用于样式表
gem'sass-rails',“~>5.0”
#使用Uglifier作为JavaScript资产的压缩器
gem'uglifier','>=1.3.0'
#将CoffeeScript用于.coffee资产和视图
gem“咖啡轨”,“~>4.2”
#看https://github.com/rails/execjs#readme 获取更多受支持的运行时
#宝石“therubyracer”,平台::ruby
#使用jquery作为JavaScript库
gem'jqueryrails'
#Turbolinks使web应用程序的导航速度更快。阅读更多:https://github.com/turbolinks/turbolinks
gem“涡轮链接”,“大于5”
#轻松构建JSON API。阅读更多:https://github.com/rails/jbuilder
gem'jbuilder',“~>2.5”
#使用Redis适配器在生产中运行操作电缆
#gem'redis',“~>3.0”
#使用ActiveModel具有\u安全\u密码
#gem'bcrypt',“~>3.1.7”
gem“引导程序”,“~>4.0.0.alpha3”
来源'https://rails-assets.org”“是吗
gem'rails assets tether','>=1.1.0'
结束
宝石“回形针”,“大于5.0.0”
gem“浏览器”
#使用Capistrano进行部署
gem“capistrano rails”,集团::开发
小组:开发,:测试
#在代码中的任意位置调用“byebug”以停止执行并获得调试器控制台
gem'byebug',平台::mri
结束
小组:发展怎么办
#在异常页面上或通过使用代码中的任意位置访问IRB控制台。
gem‘web控制台’
gem'听',“~>3.0.5”
#Spring通过让应用程序在后台运行来加速开发。阅读更多:https://github.com/rails/spring
宝石“春天”
gem‘SpringWatcherListen’,“~>2.0.0”
结束
#Windows不包括zoneinfo文件,因此捆绑tzinfo数据
gem'tzinfo data',平台:[:mingw,:mswin,:x64_mingw,:jruby]

使用bundle exec可以保证程序在gemfile中指定的环境中运行,这意味着程序的创建者希望程序在该环境中运行,这意味着无论您的计算机上有多么奇怪的设置,程序都应该正确运行


参考资料:

听起来您全局安装的
rails
命令是rails 4,这就是您所说的“它不能正常运行”的原因。运行
bundle exec
时,它使用当前
Gemfile
中的
rails
命令,因为Gemfile中有
rails 5
,所以它工作正常

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

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

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

“为了正确运行命令”是什么意思??