replicate
replicate copied to clipboard
Using a dump script with ActiveRecord models within a Rails app
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
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
Thanks @subelsky. Replicate::AR
worked for me. I didn't even need to include a require 'replicate'
initializer.