1

简而言之,我有一个 gemfile 包含

group :assets do
  gem 'my_gem'
end

my_rake_task,一个依赖于的 rake 任务:environment,一个需要的 Rails 初始化程序my_gem,以及以下 Capistrano 片段:

task :run_my_rake_task, :roles => :db do
  run "cd #{release_path} && bundle exec rake RAILS_ENV=#{rails_env} my_rake_task"
end

就目前情况而言,调用 Capistrano 配方会导致初始化程序引发错误,指出常量 frommy_gem不可用。我怎样才能使 rake 任务拉入:assets组 gems 或将另一个组添加到 gemfile 以便这个初始化程序停止破坏?(请注意,我当然可以移出my_gem小组:assets,一切正常,但这似乎是我确信可以避免的廉价黑客答案。)

4

1 回答 1

1

Open config/application.rb. Look at the top of it. Comment out this line:

Bundler.require(*Rails.groups(:assets => %w(development test)))

And uncomment this:

Bundler.require(:default, :assets, Rails.env)

So it will load your assets group gems when app loading.

But I think that if you need to use your my_gem right in the initializer of the application, then you need to move it out from assets group.

You can get more information about bundler grouping from this article: http://iain.nl/getting-the-most-out-of-bundler-groups

于 2013-03-19T19:29:56.427 回答