namespace :plant do
desc 'Puts the content from the YAML files in app/content into the database' task seed: :environment do count = 0 added_nodes = [] Plant::Utils.load_all_yaml_files.each do |full_node, value| add_object(full_node, value) added_nodes << full_node count += 1 end none = Plant::Content.where.not(node_id: added_nodes).destroy_all.count puts "Planted #{count} seeds and removed #{none} redundant seeds." end desc 'Puts the content from the YAML files in app/content into the database' task seeds: :seed desc 'Usage: rake plant:specific_seed[yaml_file.yml] imports yaml_file' task :specific_seed, [:yaml_path] => :environment do |_, args| Plant::Utils.load_yaml_file(args[:yaml_path]).each do |full_node, value| add_object(full_node, value) end end
end
# Adds the object to the database from a yaml file def add_object(full_node, value)
content_obj = Plant::Content.find_or_initialize_by(node_id: full_node) content_obj.content = value.chomp content_obj.save!
end