Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. # script/plugin install svn://insidevents.com/repository/simply_commentable/trunk simply_commentable
  2.  
  3. class Post < ActiveRecord::Base
  4. has_comments
  5. end
  6.  
  7. class User < ActiveRecord::Base
  8. posts_comments
  9. end
  10.  
  11. class Comment < ActiveRecord::Base
  12. is_comment_model
  13. end
  14.  
  15. # Generate the comments table migration:
  16. # script/generate comments_migration
  17.  
  18. >> current_user.comment_for? @post
  19. => false
  20. >> current_user.comment_for! @post
  21. => ActiveRecord::RecordInvalid: Validation failed: Title can't be blank, Comment can't be blank
  22. >> current_user.comment_for! @post, :title => "Title", :comment => "Body"
  23. => #<Comment:0xb67b8ca4 @errors=#<ActiveRecord::Errors:0xb67b7e08 @errors={}, @base=#<Comment:0xb67b8ca4 ...>>, @attributes={"commentable_type"=>"Venue", "title"=>"Title", "id"=>5, "commentable_id"=>3, "user_id"=>4, "comment"=>"Body", "created_at"=>Wed Jan 31 05:38:16 UTC 2007}, @new_record=false>
  24. >> current_user.comment_for? @post
  25. => true
  26. >> @post.comment_by? current_user
  27. => true
  28.  
  29. current_user.comments_for @post
  30. current_user.comments_for Post
  31.  
  32. @post.comments_by current_user
  33. @post.comments_by current_user.id
  34.  
  35. Comment.find_all_for @post
  36. Comment.find_all_for Post
  37. Comment.find_all_by current_user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement