rails s or bundle exec rails s

2019-02-13 15:47发布

In rails 3 does rails s invoke bundler so that you don't need to do bundle exec rails s or is bundle exec required to run rails s in your apps Gemfile environment?

Update It's understood that bundle exec should be used before rake tasks because of different rake versions. See http://railsapps.github.com/installing-rails-3-1.html for more details. This question is about rails scripts, like:

rails s
rails server
rails c
rails console

^Should bundle exec be used before these rails scripts, or is bundler invoked by the rails command?

2条回答
闹够了就滚
2楼-- · 2019-02-13 15:48

You should get this behavior in Rail >= 3.1 however you need to be careful because you may be using an older version of rake:

It’s good practice to use the command bundle exec rake instead of rake so you’ll use the version of Rake specified in your gemfile (or a dependency specified in the Gemfile.lock file) instead of the default version. For example, instead of rake db:migrate, run bundle exec rake db:migrate.

What You Need to Know: Make sure you are using Rake 0.9.2.2 (or newer) with gem update rake before installing Rails 3.1. And use bundle exec rake instead of rake.

Quoted from: http://railsapps.github.com/installing-rails-3-1.html

It looks like the opposite it true for the rails command:

don’t run bundle exec before rails command, rails already checks the presence of Bundler through the Gemfile and sets up everything according to it without the overhead of bundle exec. rails command is the only exception to the rule.

Quoted from: http://blog.wyeworks.com/2011/12/27/bundle-exec-rails-executes-bundler-setup-3-times

查看更多
闹够了就滚
3楼-- · 2019-02-13 15:51

http://bundler.io/v1.5/rails3.html - "Rails 3 comes with baked in support with bundler...Bundler is transparently managing your dependencies!" So just run the server with

rails server
查看更多
登录 后发表回答