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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Jan 13, 2010 at 1:53 PM, Artem Bu <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 curtis.cooley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org home:http://curtiscooley.com blog:http://ponderingobjectorienteddesign.blogspot.com ==============Leadership is a potent combination of strategy and character. But if you must be without one, be without the strategy. -- H. Norman Schwarzkopf -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Curtis Cooley wrote:> On Wed, Jan 13, 2010 at 1:53 PM, Artem Bu <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> and all looks great, but when i do like this >> >> 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.Thanks for answer, but i didn''t help. @page or @item are found great by find find_by_id. But i think problem occurs then app trying to find and destroy page nested in item. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 13, 4:53 pm, Artem Bu <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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. >Can you post a complete stacktrace? It will be a lot easier to figure out what the issue is. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.