I think I've got part of the solution figured out. After digging into 
the code a little and poking around console, I think I understanding 
what's going on.

page_attachments is literally attached to a page with class Page. In 
page_attachments_extension.rb, the PageAttachment stuff gets 
class_eval'ed onto Page.

----------------------
Page.class_eval {
  include PageAttachmentAssociations
  include PageAttachmentTags
}
----------------------

Also, I see in the PageAttachment class definition:

class PageAttachment < ActiveRecord::Base
  ...

  belongs_to :page
end

>From looking at a page with page type "Archive" in console:
#<ArchivePage:0x25cdc48 @attributes={"slug"=>"/", 
"class_name"=>"ArchivePage", ....

This is no longer a page with class Page, it is an ArchivePage and 
ArchivePage hasn't received the PageAttachment extensions.

As an experiment, I tried just duplicating the include code above and 
eval'ing it on ArchivePage:

----------------------
ArchivePage.class_eval {
  include PageAttachmentAssociations
  include PageAttachmentTags
}
----------------------

I restarted my server and tried to edit the page, but got stopped with 
an error:

SQLite3::SQLException: no such column: page_attachments.archive_page_id: 
SELECT count(*) AS count_all FROM page_attachments WHERE 
(page_attachments.archive_page_id = 1)

What I noticed after that was that PageAttachmentAssociations evals the 
following when it gets included into a class:

has_many :attachments, :class_name => "PageAttachment", :dependent => 
:destroy

Adding :foreign_key => "page_id" should clear up the error that just 
stopped us:

has_many :attachments, :class_name => "PageAttachment", :dependent => 
:destroy, :foreign_key => "page_id"

I restarted my server and tried to attach an image to the Archive page 
and it worked. So now, the main issue is just figuring out a way to 
include PageAttachments gracefully into all of the page types when the 
extension gets activated. Anyone have any ideas?
-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to