簡體   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