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. nirosh -- 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.
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 post: class Comment < ActiveRecord::Base belongs_to :poem belongs_to :post end class Poem < ActiveRecord::Base has_many :comments end class Post < ActiveRecord::Base has_many :comments end On May 24, 3:14 am, nirosh <kunalan.kand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > nirosh > > -- > 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 athttp://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.
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 models. You can set your models up as so: comment has_many: poems has_many: posts poem belongs_to: comment post belongs_to: comment Your poem and post tables would then each have a column/attribute: comment_id 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. HTH Paul On May 24, 8:14 am, nirosh <kunalan.kand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > nirosh > > -- > 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 athttp://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.