I have Titles and People, and I want a single Image class that can apply to either. I''m reading the Rails API on Polymorphic Associations, and I''m getting confused by the example. Can anyone explain how to do this: Title has_many :images Person has_many :images Image belongs_to [either :image or :title] Thanks very much in advance, Walter -- 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.
Image class belongs_to :image_interface, polymorphic => true Other classes has_many :images, :as => :image_interface Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 31/08/2011, at 1:16 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> I have Titles and People, and I want a single Image class that can apply to either. I''m reading the Rails API on Polymorphic Associations, and I''m getting confused by the example. Can anyone explain how to do this: > > Title > has_many :images > > Person > has_many :images > > Image > belongs_to [either :image or :title] > > Thanks very much in advance, > > Walter > > -- > 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. >-- 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.
In my opinion, this API is borked. See my other message for usage but I reckon the :as should be replaced with :using or something else Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 31/08/2011, at 1:16 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> I have Titles and People, and I want a single Image class that can apply to either. I''m reading the Rails API on Polymorphic Associations, and I''m getting confused by the example. Can anyone explain how to do this: > > Title > has_many :images > > Person > has_many :images > > Image > belongs_to [either :image or :title] > > Thanks very much in advance, > > Walter > > -- > 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. >-- 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.
Thanks very much. Good point, too. Walter On Aug 30, 2011, at 11:35 PM, Julian Leviston wrote:> In my opinion, this API is borked. See my other message for usage > but I reckon the :as should be replaced with :using or something else > > Blog: http://random8.zenunit.com/ > Twitter: http://twitter.com/random8r > Learn: http://sensei.zenunit.com/ > New video up now at http://sensei.zenunit.com/ > real fastcgi rails deploy process! Check it out now! > > > On 31/08/2011, at 1:16 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > wrote: > >> I have Titles and People, and I want a single Image class that can >> apply to either. I''m reading the Rails API on Polymorphic >> Associations, and I''m getting confused by the example. Can anyone >> explain how to do this: >> >> Title >> has_many :images >> >> Person >> has_many :images >> >> Image >> belongs_to [either :image or :title] >> >> Thanks very much in advance, >> >> Walter >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> . >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> . >> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en >> . >> > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- 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.
Yeah because what you''re doing is programming / adhering to an interface. This wording is the source of a huge amount of confusion for many programmers. Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 01/09/2011, at 12:33 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Thanks very much. Good point, too. > > Walter > > On Aug 30, 2011, at 11:35 PM, Julian Leviston wrote: > >> In my opinion, this API is borked. See my other message for usage but I reckon the :as should be replaced with :using or something else >> >> Blog: http://random8.zenunit.com/ >> Twitter: http://twitter.com/random8r >> Learn: http://sensei.zenunit.com/ >> New video up now at http://sensei.zenunit.com/ >> real fastcgi rails deploy process! Check it out now! >> >> >> On 31/08/2011, at 1:16 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> >>> I have Titles and People, and I want a single Image class that can apply to either. I''m reading the Rails API on Polymorphic Associations, and I''m getting confused by the example. Can anyone explain how to do this: >>> >>> Title >>> has_many :images >>> >>> Person >>> has_many :images >>> >>> Image >>> belongs_to [either :image or :title] >>> >>> Thanks very much in advance, >>> >>> Walter >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > -- > 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. >-- 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.
Quite often you''ll see examples trying to bake the nature of "interface" into the interface name. Things such as "attachable" or "imageable" and the like, but what this is really trying to do is say "this model can adhere to the interface named attachable". Naming the interface something strangely related to the model that provides the interface such as "attachable" is IMHO trying to "name around" a problem which needs to be more clearly labelled or re-engineered. In my opinion the idea of interface needs to be built into ruby and rails a bit better. Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now! On 31/08/2011, at 1:33 PM, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> Image class belongs_to :image_interface, polymorphic => true > > Other classes has_many :images, :as => :image_interface > > Blog: http://random8.zenunit.com/ > Twitter: http://twitter.com/random8r > Learn: http://sensei.zenunit.com/ > New video up now at http://sensei.zenunit.com/ > real fastcgi rails deploy process! Check it out now! > > > On 31/08/2011, at 1:16 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > >> I have Titles and People, and I want a single Image class that can apply to either. I''m reading the Rails API on Polymorphic Associations, and I''m getting confused by the example. Can anyone explain how to do this: >> >> Title >> has_many :images >> >> Person >> has_many :images >> >> Image >> belongs_to [either :image or :title] >> >> Thanks very much in advance, >> >> Walter >> >> -- >> 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. >> > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.