Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class User
  2. has_many :posts, :include => :comments
  3. has_many :comments, :through => :posts
  4. end
  5.  
  6. class Post
  7. belongs_to :user
  8. has_many :comments
  9. end
  10.  
  11. class Comment
  12. belongs_to :post
  13. belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
  14. end
  15.  
  16. class CommentsController
  17. def create
  18. # params[:comment] is { :text => 'Blah', :post_id => 1 }
  19. current_user.comments.create!(params[:comment])
  20. # render something
  21. end
  22. end
Add Comment
Please, Sign In to add comment