one model with two controller?

i have a comment Model. it has already "belongs_to :poem" entry.
is there any way to use this model to another controller (eg:-
belongs_to :post) . if it is possible then how do i do the migration
and other stuffs please explain a bit.


I don't think controllers have anything to do with your question. A
controller is a program that receives requests from the browser and
processes them, most likely involving models, and then sends a
response back to the browser.

What you are talking about, I think, is about activerecord
associations. You can make as many associations between models
(tables) as you wish. A comment can belong to a poem and also to a

class Comment < ActiveRecord::Base
  belongs_to :poem
  belongs_to :post

class Poem < ActiveRecord::Base
  has_many :comments

class Post < ActiveRecord::Base
  has_many :comments

Hi nirosh,

belongs_to associations represent other models/tables not controllers.

You can have as many different Controllers as you like, created
through migrations or manually - they are simply the way of 'getting
in' to your application. All the heavy lifting should be done in the

You can set your models up as so:

    has_many: poems
    has_many: posts

    belongs_to: comment

    belongs_to: comment

Your poem and post tables would then each have a column/attribute:

Each poem and each post could then 'attach' themselves to the same
comment_id so that each single comment could be associated with both a
poem and a post.

You create your post migration the same way you created your poem
migration, apart from any additional attributes specifically related
to post.