Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # script/plugin install svn://insidevents.com/repository/simply_commentable/trunk simply_commentable
- class Post < ActiveRecord::Base
- has_comments
- end
- class User < ActiveRecord::Base
- posts_comments
- end
- class Comment < ActiveRecord::Base
- is_comment_model
- end
- # Generate the comments table migration:
- # script/generate comments_migration
- >> current_user.comment_for? @post
- => false
- >> current_user.comment_for! @post
- => ActiveRecord::RecordInvalid: Validation failed: Title can't be blank, Comment can't be blank
- >> current_user.comment_for! @post, :title => "Title", :comment => "Body"
- => #<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>
- >> current_user.comment_for? @post
- => true
- >> @post.comment_by? current_user
- => true
- current_user.comments_for @post
- current_user.comments_for Post
- @post.comments_by current_user
- @post.comments_by current_user.id
- Comment.find_all_for @post
- Comment.find_all_for Post
- Comment.find_all_by current_user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement