Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heroku run rake > no such file to load -- faker

When running 'heroku run rake' I get this error:

  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)>'

I have gem 'faker', '0.3.1' under group :development, :test do in Gemfile.

I have require 'faker' in sample_data.rake

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
like image 723
Cornelius Wilson Avatar asked Feb 04 '13 16:02

Cornelius Wilson


2 Answers

Heroku does not install test or development gems by default.

If you want to load fake in your production, you should remove gem 'faker', '0.3.1' from the group :development, :test do and place it outside any group:

  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'
  ...

However, if you don't want to load fake, you must ensure that your require fake will be required only when the task is invoked:

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

Hope it helps.

EDIT

You can tell Bundler to not load the Gem by:

 gem 'faker', '0.3.1', :require => false
like image 142
gabrielhilal Avatar answered Nov 07 '22 02:11

gabrielhilal


I got this issue with the "Rub on Rails 3 Tutorial". Per gabrielhilals answer, the fix was to move require 'faker' to inside the task

before fix:

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

after fix:

namespace :db do
  require 'faker'
  desc "Fill database with sample data"
  task :populate => :environment do
    ...
    ...
  end
end
like image 37
KeithP Avatar answered Nov 07 '22 01:11

KeithP