← Back to Upcase

Rake task to return users created by faker gem


(Mike Munroe) #1

I am using the faker gem to create 10 sample users in my app that has authentication. Sign in requires a valid email address.

I would like to return email addresses for the users created by faker to new developers building the app.

I think the best way to do this is to have the developers run a rake task, such as rake app:user_info to output email addresses to the console, so that they know valid email addresses in the database that can be used to login.

What is the best way to make a call to the db through a rake task? Or is there another suggestion on a better way to return valid email addresses created by faker to a developer other than having them query the db?


(Ben Orenstein) #2

Even though it’s kind of heavy-handed, I’d make booting the Rails environment a prerequisite of my rake task. That way the database connection is created for you, and you can just use ActiveRecord to display the emails.