繁体   English   中英

Rails 5:Rails s..bundle exec rails。

[英]Rails 5: rails s vs. bundle exec rails s

我是第一次在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]

听起来您全局安装的rails命令是rails 4,这就是您说的“它无法正常运行”的原因。 当您运行bundle exec它将使用当前Gemfilerails命令,因为您的Gemfilerails 5 ,那么它可以正常工作。

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

例如,当我cd到我的项目的目录,我得到这样的消息:

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

使用bundle exec可以保证程序在gemfile中指定的环境下运行,这意味着它是程序创建者希望在其中运行的环境,这意味着无论您使用哪种怪异的设置,它都应该正确运行。在您的计算机上。

参考: 使用bundle exec rake还是只是rake?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM