Problem with polymorphic

Hi all! I have a strange problem when i try to use polymorphic associations in my app. I have a simple relations between my models:

class Item < ActiveRecord::Base   belongs_to :content, :polymorphic => true, :dependent => :destroy

class Page < ActiveRecord::Base   has_one :item, :as => :content, :dependent => :destroy

When i add a new Item everything works fine, all associations creates and all looks great, but when i do like this

@item = Item.find(1) @item.destroy

or even when i try to do this @page = Item.find(1) @page.destroy

I get "ActiveRecord::RecordNotFound: Couldn't find Page without an ID" error.

Of course, page and item with id=1 are exist.

What i did wrong?

Not sure if it'll help, but I've found find_by_id more developer friendly than find. You could try it and see what results you get. I'm betting a NoMethodError on nil for delete.

Curtis Cooley wrote:

Can you post a complete stacktrace? It will be a lot easier to figure out what the issue is.

--Matt Jones