Rake tasks comatose:data:import

4 views
Skip to first unread message

hunkybill

unread,
Dec 1, 2008, 2:58:25 PM12/1/08
to Comatose Plugin
Hi,

I have a very nice Comatose installation, with one small issue bugging
me. From the rake task data:import, line 60

target = (root == '') ? ComatosePage.root : ComatosePage.find_by_path
(root)

I bootstrap my application using a rake task. When I do this, I use
the same line from the Comatose Migration to create a Root, namely

root = ComatosePage.create( :title=>'Root', :body=>"h1. Comatose Root
Page", :author=>'System' )

When run inside the migration rake task, this line executes with no
problem, and a call to ComatosePage.root returns this node. However, I
noticed with my bootstrap, ComatosePage.root was always returning nil.
Closer inspections revealed my root create failing with a message
about no Parent. I see no parent_id in my call, so I added :parent_id
=> nil. Same validation error. The ComatosePage model has this line...

validates_presence_of :parent_id, :on=>:create, :message=>"must be
present"

Which leads me to now question how the migration works in the first
place! The migration is clearly using the Model for ComatosePage,
which clearly has this validator, which fails when I go rake or script/
console... but inside the migration it works fine and dandy....

Can anyone shed light on this for me.

Thanks

Andrew Kuklewicz

unread,
Dec 1, 2008, 6:07:50 PM12/1/08
to comatos...@googlegroups.com
The migration I had disabled this validation on initial creation of the root page by defining comatose page without it -

class ComatosePage < ActiveRecord::Base
  set_table_name 'comatose_pages'
  acts_as_versioned :table_name=>'comatose_page_versions', :if_changed => [:title, :slug, :keywords, :body]
end

Cheers,
-Andrew
--
Andrew Kuklewicz
Reply all
Reply to author
Forward
0 new messages