[英]Rails 5: rails s vs. bundle exec rails s
I'm starting a project on Rails 5 for the first time and I was curious why running 'rails s' when I was on Rails 4 worked fine, but now that I'm on Rails 5 I need to preface it with 'bundle exec' in order to run the command properly. 我是第一次在Rails 5上启动一个项目,我很好奇为什么在Rails 4上运行'rails s'可以正常工作,但是现在在Rails 5上,我需要以'bundle exec'开头以正确运行命令。
Below is my Gemfile. 以下是我的Gemfile。 Again, everything works normally if I preface all my rails commands with.
同样,如果我以所有rails命令开头,则一切正常。 I'm just curious if anyone else experiencing this or if someone can give me some insight as to why this is happening?
我只是想知道是否还有其他人正在经历这种情况,或者有人可以给我一些有关为什么发生这种情况的见解?
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]
It sounds like the rails
command you have installed globally is rails 4 and it's the reason "it doesn't run properly" like you say. 听起来您全局安装的
rails
命令是rails 4,这就是您说的“它无法正常运行”的原因。 When you run bundle exec
then it uses the rails
commands from the current Gemfile
, since you have rails 5
in your Gemfile then it works properly. 当您运行
bundle exec
它将使用当前Gemfile
的rails
命令,因为您的Gemfile
有rails 5
,那么它可以正常工作。
I'd recommend using either RVM or rbenv , I personally like RVM since it switches automatically to the gemset of the ruby version specified in my Gemfile. 我建议使用RVM或rbenv ,我个人喜欢RVM,因为它会自动切换到我的Gemfile中指定的ruby版本的gemset。
Example, when I cd
into the directory of my project I get a message like: 例如,当我
cd
到我的项目的目录,我得到这样的消息:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too.
RVM使用您的Gemfile选择Ruby,这很好-Heroku也这样做。
Using bundle exec guarantees that the program is run with the environment specified in the gemfile, which hopefully means it is the environment that the creators of the program want it to be run in, which hopefully means it should run correctly no matter what weird setup you have on your computer. 使用bundle exec可以保证程序在gemfile中指定的环境下运行,这意味着它是程序创建者希望在其中运行的环境,这意味着无论您使用哪种怪异的设置,它都应该正确运行。在您的计算机上。
Reference: Use bundle exec rake or just rake? 参考: 使用bundle exec rake还是只是rake?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.