Using Faker gem on Rails 3.2.13 and ruby 1.9.3p545

276 views
Skip to first unread message

Megan Byrne

unread,
Jul 15, 2014, 4:13:45 PM7/15/14
to ruby-...@googlegroups.com
Hello all,

So let me first state for the record that I am very new to Rails Development and programming in general, so the answer to this may be fairly obvious.  I am currently working on some legacy code as a contractor and am running into quite a few problems with versions of gems, since prior to now I have only used Rails 4 and Ruby 2.

Here's the problem:

I'm trying to write a rake task that would be ideal to incorporate the Faker gem with.  I've just specified " gem 'faker' " in the gem file and ran Bundle install.  Also, started writing the rake task which includes "require 'faker' ".  But now that I try to run the rials server, I get an error message in terminal that starts out like this:

/Users/megaputer/.rvm/gems/ruby-1.9.3-p545/gems/faker-1.4.1/lib/faker.rb:10:in `<top (required)>': undefined method `enforce_available_locales=' for I18n:Module (NoMethodError)

I'm really not sure how to proceed, I suspect that I need to specify a specific version of Faker to work with Rails 3.2.13 and Ruby 1.9.3p545, but I haven't been able to find much on my own searching online.

Please Help!

Thanks in advance,

Megan

Conrad Taylor

unread,
Jul 15, 2014, 6:09:07 PM7/15/14
to ruby-...@googlegroups.com
Megan, did you get this issue resolved?  If not, are you using the following for development and/or test.  If this is the case, I would recommend using the following:


You'll want to add it to your development group within your Gemfile.  Next, 'bundle install'.  So, can you show the rake file?

--

Think different and code well,

-Conrad

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/d/optout.

Benjamin Curtis

unread,
Jul 15, 2014, 6:51:23 PM7/15/14
to ruby-...@googlegroups.com
The problem is most likely an old version of the i18n gem.  Try upgrading that.

Conrad Taylor

unread,
Jul 15, 2014, 7:05:17 PM7/15/14
to ruby-...@googlegroups.com
Benjamin, an outdated i18n gem could very well be the cause of the issue.


--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/d/optout.

Conrad Taylor

unread,
Jul 18, 2014, 4:08:50 PM7/18/14
to ruby-...@googlegroups.com
Megan, if you're simply needing to seed a local development database, you can simply use seeds.rb file.  Next, here's a sample rake file:

namespace :db do
  desc "Create user records in the current database."

  task :fake_users => :environment do
    require 'faker'

    @countries = ["United States", "Canada", "United Kingdom", "Germany", "Mexico"]
    @genders = ["Male","Female"]
    @privacy = ["members", "public"]
    
    def random_date(params={})
      years_back = params[:year_range] || 5
      latest_year = params [:year_latest] || 0
      year = (rand * (years_back)).ceil + (Time.now.year - latest_year - years_back)
      month = (rand * 12).ceil
      day = (rand * 31).ceil
      date = Time.now
      series = [date]
      if params[:series]
        params[:series].each do |some_time_after|
          series << series.last + (rand * some_time_after).ceil
        end
        return series
      end
      date
    end
    
    100.times do
        User.create!(
        :first_name => Faker::Name.first_name,
        :last_name => Faker::Name.last_name,
        :birthdate => random_date(:year_range => 60, :year_latest => 22),
        :created_at => random_date(:year_range => 4, :year_latest => 0),
        :city => Faker::Lorem.words(1).to_s.capitalize,
        :state => Faker::Address.us_state(),
        :country => @countries.rand.to_s,
        :password => "foobar",
        :password_confirmation => "foobar",
        :accepts_terms_and_conditions => true,
        :gender => @genders.rand.to_s,
        :email => Faker::Internet.email
      )
    end
  end
end
I suspect that your issue was that Rails environment wasn't being properly loaded.  In any case, I wish that the above example helps.

--

Think different and code well,

-Conrad

Sent from my iPhone

On Jul 15, 2014, at 1:13 PM, Megan Byrne <megan....@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages