replicate icon indicating copy to clipboard operation
replicate copied to clipboard

Using a dump script with ActiveRecord models within a Rails app

Open axsuul opened this issue 12 years ago • 2 comments

I'm running into issues using a dump script on ActiveRecord objects within a Rails application. Here is my dump script config/replicate/dump.rb

# config/environment
require File.dirname(File.dirname(File.expand_path(__FILE__))) + "/environment"

Post.all.each do |post|
  dump post
end

Running

replicate -d config/replicate/dump.rb > test.dump

gives the error

Post must respond to #dump_replicant (NoMethodError)

Does this mean replicate is somehow not being required? However, I am definitely requiring replicate in my config/environment

# Load the rails application
require File.expand_path('../application', __FILE__)

require 'replicate'

# Initialize the rails application
TestApp::Application.initialize!

What's strange is that this works fine.

replicate -r config/environment -d "Post.all" > test.dump

axsuul avatar May 17 '12 08:05 axsuul

I had the same problem - seems to be related to how replicate uses autoload. Adding this to my dump.rb file forced replicate to load itself:

Replicate::AR

subelsky avatar Sep 07 '12 16:09 subelsky

Thanks @subelsky. Replicate::AR worked for me. I didn't even need to include a require 'replicate' initializer.

audionerd avatar Jan 15 '15 22:01 audionerd