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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

