heroku run rake>没有这样的文件加载 - faker

时间:2013-02-04 16:47:31

标签: ruby-on-rails heroku

运行'heroku run rake'时出现此错误:

  no such file to load -- faker
/app/lib/tasks/sample_data.rake:1:in `require'
/app/lib/tasks/sample_data.rake:1:in `<top (required)>'

我有宝石'faker','0.3.1'在group:development下,:test在Gemfile中。

我在sample_data.rake中要求'faker'

source 'https://rubygems.org'

gem 'rails', '3.2.11'
gem 'gravatar_image_tag', '0.1.0'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.8'
 gem 'guard-spork', '1.2.0'
 gem 'faker', '0.3.1'
  gem 'spork', '0.8.4'
  gem 'will_paginate', '3.0'
gem 'webrat', '0.7.1'
 gem 'capybara', '1.1.2'
gem 'annotate', '2.5.0'
gem 'factory_girl_rails', '1.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.2'

group :production do
  gem 'pg', '0.12.2'
end

2 个答案:

答案 0 :(得分:9)

默认情况下,Heroku不会安装testdevelopment个宝石。

如果您想在制作中加载fake,则应从gem 'faker', '0.3.1'移除group :development, :test do并将其放在任何群组之外:

  source 'https://rubygems.org'
  gem 'rails', '3.2.11'
  gem 'gravatar_image_tag', '0.1.0'
  gem 'faker', '0.3.1'

  group :development, :test do
  gem 'sqlite3', '1.3.5'
  ...

但是,如果您不想加载fake,则必须确保仅在调用任务时才需要require fake

task :sample_data => :environment do
  require 'faker'  #must be inside the task.
  ...
end

希望它有所帮助。

修改

您可以通过以下方式告诉Bundler不加载Gem:

 gem 'faker', '0.3.1', :require => false

答案 1 :(得分:1)

我在“Rub on Rails 3 Tutorial”中遇到了这个问题。 根据gabrielhilals的回答,解决方法是将'faker'移到任务内部

修复前的

require 'faker'
namespace :db do
  desc "Fill database with sample data"
  task :populate => :environment do
    ...
    ...
  end
end
修复后

namespace :db do
  require 'faker'
  desc "Fill database with sample data"
  task :populate => :environment do
    ...
    ...
  end
end