I'm working on a rake task for a Rails project which is separated into multiple engines. The task is located in the
lib/tasks folder of the main Rails application, and is attempting to create a new
Post from the
Blog engine (
The engine file (
blog/lib/blog/engine.rb) looks like:
module Blog class Engine < ::Rails::Engine isolate_namespace Blog end end
So if I'm understanding correctly, referencing
Blog::ModelHere is the correct syntax. Here's the rake task:
namespace :blog do desc "Import blog posts from old Wordpress site" task :import => :environment do # ... generating variables here post = Blog::Post.create!( post.title = title, post.slug = title.parameterize, post.date = date, post.user_id = User.find_by_name(user).id, post.content = content, post.tags = tags ) end end
undefined method 'title=' for nil:NilClass
It seems to choke on the
Blog::Post call. I've tried
::Blog::Post as well, but that didn't seem to make much sense. I've also tried keeping it in
blog/lib/tasks as an engine task, but I couldn't get that working either.
I've looked around SO and Github to see if anyone has code up for rake tasks within engines, but couldn't find anything concrete. Any ideas?