gpt4 book ai didi

ruby-on-rails - 我应该使用 `bundle exec` 还是 Rails 的 binstubs?

转载 作者:行者123 更新时间:2023-12-01 03:21:39 33 4
gpt4 key购买 nike

假设我有一个安装了 gems 的 Rails 应用程序 bundler .我应该使用 bundle exec railsbin/rails ?我应该使用 bundle exec rakebin/rake ?有什么区别吗?其中有一个比另一个更好吗?

最佳答案

tl;博士 没有特别的区别,但如果我要选择,我会使用 bin/rails几乎没有区别。让我们来看看。DISABLE_SPRING=1 bin/rails --version :bin/rails : require_relative '../config/boot'
config/boot : require 'bundler/setup'
bundler/setup : Bundler.setup
Bundler.setup : definition.validate_runtime!
Bundler.definition : Definition.build
Bundler::Definition.build : Dsl.evaluate
Bundler::Dsl.evaluate : builder.eval_gemfile
Bundler::Dsl#eval_gemfile : instance_eval
require 'bundler/setup' ,试图 gem 'rails', 'x.y.z'结果是:

*** Gem::LoadError Exception: can't activate rails (= x.y.z), already activated rails-5.1.3. Make sure all dependencies are added to Gemfile.


bundle exec rails --version ,我们最终运行 bin/rails反正: ~/.gem/ruby/x.y.z/bin/rails : load Gem.activate_bin_path('railties', 'rails', version)
exe/rails : require 'rails/cli'
rails/cli : Rails::AppLoader.exec_app
Rails::AppLoader.exec_app : `exec RUBY, 'bin/rails', *ARGV
另外,请注意可以在 last file 中找到的消息。 :

Beginning in Rails 4, Rails ships with a rails binstub at ./bin/rails that should be used instead of the Bundler-generated rails binstub.


所以,在一天结束时没有区别。但是考虑到 Rails 在运送自己的 binstub 时遇到了麻烦,我更喜欢 bin/rails选择。此外,它自动完成更好。
和,

App executables now live in the bin/ directory: bin/bundle, bin/rails, bin/rake. Run rake rails:update:bin to add these executables to your own app. script/rails is gone from new apps.

Running executables within your app ensures they use your app's Ruby version and its bundled gems, and it ensures your production deployment tools only need to execute a single script. No more having to carefully cd to the app dir and run bundle exec ....

Rather than treating bin/ as a junk drawer for generated "binstubs", bundler 1.3 adds support for generating stubs for just the executables you actually use: bundle binstubs unicorn generates bin/unicorn. Add that executable to git and version it just like any other app code.


https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md

关于ruby-on-rails - 我应该使用 `bundle exec` 还是 Rails 的 binstubs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688321/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com