Last active
May 23, 2016 09:42
-
-
Save iberianpig/0d977156c0474bd3be86bfd73fe7bcc9 to your computer and use it in GitHub Desktop.
db:dump_seed_fu[model]で実行。 db:seed_fuで使えるseedデータがdb/fixtures内に生成されるrake task。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./lib/tasks/db.rake | |
require 'active_record' | |
@logger = Logger.new(STDOUT) | |
namespace :db do | |
desc "Make seed data importable with seed_fu" | |
task :dump_seed_fu, [:model] => :environment do |t, args| | |
model_name = args.model.underscore | |
class_name = args.model.camelize | |
seed = SeedFu::Writer.write("db/fixtures/#{model_name.pluralize}.rb", class_name: "#{class_name}") do |writer| | |
Object.const_get("#{class_name}").order(:id).find_each do |m| | |
writer << m.attributes | |
end | |
end | |
@logger.info "create db/fixtures/#{model_name.pluralize}.rb" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment