Last active
August 29, 2015 14:05
-
-
Save amoose/e8cbd5812fc41668a8cb to your computer and use it in GitHub Desktop.
Imports Articles from fixtures
This file contains hidden or 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
require 'yaml' | |
namespace 'import' do | |
desc "Imports sample Answers data from fixtures/articles.yml" | |
task :articles => :environment do | |
puts "Loading Answers data from spec/fixtures/articles.yml" | |
@questions = YAML::load_file('spec/fixtures/articles.yml') | |
@questions.each do |question| | |
q = question.second | |
article = Article.create( | |
:title => q['title'], | |
:type => q['type'], | |
:content_main => q['content_main'], | |
:content_need_to_know => q['content_need_to_know'], | |
:tags => q['tags'], | |
:preview => q['preview'], | |
:category_id => q['category_id'], | |
:status => 'Published' | |
) | |
puts "Created new Article: #{article.title}\n" | |
end | |
puts "\n\n" | |
puts "Imported #{@questions.size} questions" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
drop in
lib/tasks