Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3501710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:53:37+00:00 2026-05-18T12:53:37+00:00

(This is really a newbie question about Rake & Rails & dependencies in general.

  • 0

(This is really a newbie question about Rake & Rails & dependencies in general. Trying to wrap my head around how all this fits together)

Basically, I want a Rake task that acts like seed.rb but is called separately. It adds test data for the development environment, while my seed.rb provides basic data for all environments.

The script, family_seed.rb, uses FactoryGirl to generate some records. It looks like this:

require File.expand_path('../../config/environment', __FILE__)
require './spec/factories'

Family.delete_all
Member.delete_all
zinsser = Factory.create(:family, :last_name=>'Zinsser', :first_name=>'Carl', :sim_id => '500')
blackburn = Factory.create(:family, :last_name=>'Blackburn', :first_name=>'Greg', :sim_id => '501')

It runs fine with bundle exec "ruby db/family_seeds.rb", but my question is how to set it up with Rake. Should the whole thing be placed inside a Rake task? How could I, instead, set up a task that would call the script, while ensuring that the Rails development environment is available when it runs? I’m trying not just to get the job done, but to do it in a “right” way.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:53:38+00:00Added an answer on May 18, 2026 at 12:53 pm

    One way to approach this would be to create a class or module in lib (this makes it easier to write tests for, and makes the code more reusable):

    require '../spec/factories'
    
    class FamilySeed
    
      def self.seed
        raise "Don't run this in production!" if Rails.env.production?
    
        Family.delete_all
        Member.delete_all
        zinsser = Factory.create(:family, :last_name=>'Zinsser', :first_name=>'Carl', :sim_id => '500')
        blackburn = Factory.create(:family, :last_name=>'Blackburn', :first_name=>'Greg', :sim_id => '501')
      end
    
    end
    

    How to create the rake task:

    require 'family_seed'
    
    namespace :seed do
      task :families => :environment do
        FamilySeed.seed
      end
    end
    

    I’d be careful with allowing things like Family.delete_all and Member.delete_all to be too freely used. You could easily shoot yourself in the foot later on by calling something you didn’t mean to on a production db.

    How to run the rake task:

    Run it in your command like with the following:

    bundle exec rake seed:families
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really stupid newbie-sounding question to you developer type people, but
I'm really new to VSTO so sorry if this is a newbie question. I'm
I'm just curious about this really, does anyone know why they broke convention on
So I didn't see a question here that really answers this question. It's kinda
im a newbie to flash,and i hav got this really weird problem.i have created
This really, really urks me, so I hope that someone can give me a
This really has my stumped today. I'm sure its simple, but... Here is my
Is this really the easiest way to do this? http://simplesamples.info/MFC/Clipboard.php
I just came across a C++ SDK that makes heavy use of this really
This is really only easy to explain with an example, so to remove the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.