In my app, I want to let users mark various relationship between them
and other users and objects. Example
john selects mary as favorite user
john selects mary as featured user of the month
john puts mary in bookmarks
john selects "funny cat" as favorite picture
john votes for "funny cat" as featured picture of the month
john puts "funny cat" in bookmarks
I could have a bookmark model, a favorite model, and a feature model
and use polymorphic association. But this seems like a lot of
duplication.
acts_as_favorable
acts_as_bookmarkable
acts_as_featureable
I really just want to say something like
acts_as_markable :models => [:favorite,:bookmark,:feature]
u=User.find_ny_name(''john'')
p=Picture.find 10
u.mark_favorite( p)
u.mark_feature( p)
u2 = User.find_by_name(''mary'')
u.mark_bookmark( u2)
u.marked_bookmark?( u2) # true
u.marked_favorite_users # list of favorite users
Suggestions?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
rubynuby wrote:> In my app, I want to let users mark various relationship between them > and other users and objects. > > I could have a bookmark model, a favorite model, and a feature model > and use polymorphic association. But this seems like a lot of > duplication. > > acts_as_favorable > acts_as_bookmarkable > acts_as_featureable > > I really just want to say something like > > acts_as_markable :models => [:favorite,:bookmark,:feature]What you want is the wonderful has_many_polymorphs => http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/files/README.html - Niels. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 22, 12:28 pm, Niels Ganser <ni...-nRYBEV4l/tGYhCYXZFeMvg@public.gmane.org> wrote:> rubynuby wrote: > > In my app, I want to let users mark various relationship between them > > and other users and objects. > > > I could have a bookmark model, a favorite model, and a feature model > > and use polymorphic association. But this seems like a lot of > > duplication. > > > acts_as_favorable > > acts_as_bookmarkable > > acts_as_featureable > > > I really just want to say something like > > > acts_as_markable :models => [:favorite,:bookmark,:feature] > > What you want is the wonderful has_many_polymorphs =>http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/files/... > > - Niels.Thanks, I read the doc several times but I still don''t get how I can use it in my case. It seems I still need a separate join model for favorite, bookmark, etc. ?? --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You may be able to use a combination of Single Table Inheritance and polymorphic associations. STI would handle distinguishing bookmarks from favorites from features, etc while allowing them all to share the ''mark'' behavior. Polymporphic associations, as I think you already understood, would allow you to ''mark'' an object of any type. On Mar 23, 1:23 pm, rubynuby <dear...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 22, 12:28 pm, Niels Ganser <ni...-nRYBEV4l/tGYhCYXZFeMvg@public.gmane.org> wrote: > > > > > rubynuby wrote: > > > In my app, I want to let users mark various relationship between them > > > and other users and objects. > > > > I could have a bookmark model, a favorite model, and a feature model > > > and use polymorphic association. But this seems like a lot of > > > duplication. > > > > acts_as_favorable > > > acts_as_bookmarkable > > > acts_as_featureable > > > > I really just want to say something like > > > > acts_as_markable :models => [:favorite,:bookmark,:feature] > > > What you want is the wonderful has_many_polymorphs =>http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/files/... > > > - Niels. > > Thanks, I read the doc several times but I still don''t get how I can > use it in my case. It seems I still need a separate join model for > favorite, bookmark, etc. ??--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---