【问题标题】:heroku rake db:migrate > no such file to load -- fakerheroku rake db:migrate > no such file to load -- faker
【发布时间】:2011-06-28 04:22:00
【问题描述】:

我第一次尝试将 rails 3 应用程序部署到 heroku。它似乎可以推起来,但是当我尝试运行时

heroku rake db:migrate

我收到以下错误:

rake aborted!
no such file to load -- faker
/app/98c71cc3-375f-4397-9de3-034dd7268be3/home/Rakefile:7
(See full trace by running task with --trace)
(in /app/98c71cc3-375f-4397-9de3-034dd7268be3/home)

这是我的 rakefile(第 7 行是最后一个):

require File.expand_path('../config/application', __FILE__)
require 'rake'

SampleApp::Application.load_tasks

现在我有一个名为 sample_data.rake 的任务,它使用 faker gem 用示例数据填充开发数据库,​​并且该任务具有以下行:

require 'faker'

在顶部,这一定是导致问题的原因。

我该如何解决这个错误,或者有没有办法让 heroku 忽略这个任务文件?无论如何,我不想用无意义的示例数据填充生产版本。

顺便说一句,faker 只在我的 gemsfile 中的开发环境中活跃:

# gemfiles for the rspec testing environment
group :development do
  gem 'rspec-rails', '2.5.0'
  gem 'annotate-models', '1.0.4'
  gem 'faker', '0.3.1'
end

【问题讨论】:

    标签: ruby-on-rails-3 heroku


    【解决方案1】:

    我也在 lib/tasks/sample_data.rake 文件中注释掉了 require 'faker' 并且(在通过 git 提交此更改后)将文件推送到 heroku,这允许 $heroku rake db:migrate --app <my app name> 成功执行,于是 heorku 网站又开始工作了。

    谢谢!

    【讨论】:

      【解决方案2】:

      对我来说,Simone 的第一种方法行不通,但第二种方法行得通:require 'faker' 可以从 rake 文件中删除。

      【讨论】:

        【解决方案3】:

        将 require 语句移动到任务中。 比如

        # sample_data.rake
        require 'faker'
        
        task :sample_data => :environment do
         # ...
        end
        

        # sample_data.rake
        task :sample_data => :environment do
          require 'faker'
        
         # ...
        end
        

        这样,只有在调用任务时才需要该库。

        另一种选择是在你的 rake 文件中不需要 Faker。 实际上,在开发中执行 bundle 时,Bundler 已经加载了它。

        如果您不希望 Bundler 加载 Gem,请使用

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

        【讨论】:

        • 第一个解决方案对我不起作用,但添加 :require => false 确实
        猜你喜欢
        • 2012-06-24
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        • 2012-10-07
        • 1970-01-01
        • 1970-01-01
        • 2011-04-27
        • 1970-01-01
        相关资源
        最近更新 更多