Skip to content

Instantly share code, notes, and snippets.

@amoose
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amoose/e8cbd5812fc41668a8cb to your computer and use it in GitHub Desktop.
Save amoose/e8cbd5812fc41668a8cb to your computer and use it in GitHub Desktop.
Imports Articles from fixtures
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
@amoose
Copy link
Author

amoose commented Aug 20, 2014

drop in lib/tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment