heroku rake db:migrate>没有这样的文件加载 - faker [英] heroku rake db:migrate > no such file to load -- faker
问题描述
我正在尝试第一次部署一个rails 3应用到heroku。它似乎推高了正常,但当我尝试运行时
heroku rake db:migrate
$ c $
>耙子中止了!
没有这样的文件加载 - faker
/ app / 98c71cc3-375f-4397-9de3-034dd7268be3 / home / Rakefile:7
(通过使用--trace运行任务查看完整跟踪)
(in / app / 98c71cc3-375f-4397-9de3-034dd7268be3 / home)
这是我的rakefile(第7行是最后一个):
需要File.expand_path('../ config / application', __FILE__)
需要'rake'
SampleApp :: Application.load_tasks
现在我有一个名为sample_data.rake的任务,它使用faker gem用示例数据填充开发数据库,该任务包含以下行:
要求'faker'
在顶部必须是导致问题的原因。
我该如何解决这个错误,或者有没有办法让我Herku忽略这个任务文件?我不打算用无意义的样本数据填充生产版本。
顺便说一句,faker只在我的gemsfile的开发环境中有效:
#用于rspec测试环境的gemfiles
组:开发do
gem'rspec-rails',' 2.5.0'
gem'annotate-models','1.0.4'
gem'faker','0.3.1'
end
解决方案将require语句移入任务中。
例如
#sample_data.rake
需要'faker'
任务:sample_data => :环境做
#...
结束
到
#sample_data.rake
task:sample_data => :environment do
require'faker'
#...
end
通过这种方式,只有在任务被调用时才需要该库。
另一种选择是在rake文件中不需要Faker 。
实际上,Bundler已经在bundle中执行时加载了它。
如果你不想让Bundler加载Gem,使用
gem'faker','0.3.1',:require =>假
I'm trying to deploy a rails 3 app to heroku for the first time. It seems to push up ok but when I try to run
heroku rake db:migrate
I get the following error:
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)
Here's my rakefile (line 7 is the last one):
require File.expand_path('../config/application', __FILE__)
require 'rake'
SampleApp::Application.load_tasks
Now I have a task called sample_data.rake which uses the faker gem to populate the development database with sample data and that task has the line:
require 'faker'
at the top which must be what's causing the problem.
How can I fix this error or is there a way that I can get heroku to ignore this task file? I'm not going to want to populate the production version with nonsense sample data anyway.
By the way, faker is only active in the development environment in my 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
解决方案 Move the require statement into the task.
For instance
# sample_data.rake
require 'faker'
task :sample_data => :environment do
# ...
end
to
# sample_data.rake
task :sample_data => :environment do
require 'faker'
# ...
end
In this way, the library will be required only when the task is invoked.
The other alternative is to not require Faker in your rake file.
In fact, it is already loaded by Bundler when the bundle is executed in development.
If you don't want Bundler to load the Gem, use
gem 'faker', '0.3.1', :require => false
这篇关于heroku rake db:migrate>没有这样的文件加载 - faker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!