I''m building a type of CMS and have a question about sharing code/ tables. So i have a typical blog setup with a ''posts'' controller which has many comments. I need to also make an ''article'' controller which is similar to posts but different enough that it needs its own controller. Comments though will work exactly the same. Rather than remake the comments table/code (i.e. ''article_comments'' controller), i''d prefer to just share the general comments controller/table. Is there a way to do this? Table schema for comments table would then be something like:> ID > CommentBody > BelongsToType (i.e. category ''article'', ''post'', etc) > ParentID (i.e. a specific ''articleID'', ''postID'')(BelongsToType column wouldnt be needed if I could make the post or article ID unique across both of those tables though). Any thoughts? Thanks so much, Armen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Armen Arevian wrote:> I''m building a type of CMS and have a question about sharing code/ > tables. So i have a typical blog setup with a ''posts'' controller > which has many comments. I need to also make an ''article'' controller > which is similar to posts but different enough that it needs its own > controller. Comments though will work exactly the same. Rather than > remake the comments table/code (i.e. ''article_comments'' controller), > i''d prefer to just share the general comments controller/table. Is > there a way to do this?Hi Armen I think you should look into polymorphic associations. Something along the lines of: class Comment < ActiveRecord::Base belongs_to :attachable, :polymorphic => true end class Post has_many :comments, :as => :attachable end class Article has_many :comments, :as => :attachable end should work. Check out the API at http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html -- 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-/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 -~----------~----~----~----~------~----~------~--~---