Class: CommentsController
- Inherits:
-
BumbleController
- Object
- ActionController::Base
- BumbleController
- CommentsController
- Defined in:
- app/controllers/comments_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reject ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#approve ⇒ Object
88 89 90 91 92 |
# File 'app/controllers/comments_controller.rb', line 88 def approve @comment = Comment.find(params[:id]) @comment.mark_as_ham! redirect_to post_path(@comment.post, :anchor => dom_id(@comment)) end |
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/comments_controller.rb', line 5 def create @post = Post.find(params[:post_id]) @comment = Comment.new(params[:comment]) @comment.user = current_user @comment.request = request @comment.post = @post if @comment.save respond_to do |format| format.html do if @comment.approved? flash[:notice] = 'Create successful!' else flash[:notice] = "Your comment looks like spam, it will show up once it's been approved." end redirect_to post_path(@post, :anchor => dom_id(@comment)) end format.js do if @comment.approved? render @comment, :content_type => :html else render :text => "Your comment looks like spam, it will show up once it's been approved.", :status => 406, :content_type => :html end end end else respond_to do |format| format.html { render :action => "new" } format.js { render :text => @comment.errors..join(', ').capitalize, :status => 403, :content_type => :html } end end end |
#destroy ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/comments_controller.rb', line 48 def destroy @comment = Comment.find(params[:id]) @comment.destroy respond_to do |format| format.html do flash[:notice] = 'Record deleted!' redirect_to post_path(@comment.post) end format.js { render :nothing => true } end end |
#edit ⇒ Object
75 76 77 |
# File 'app/controllers/comments_controller.rb', line 75 def edit @comment = Comment.find(params[:id]) end |
#index ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/comments_controller.rb', line 38 def index @post = Post.find(params[:post_id]) @comments = @post.comments respond_to do |format| format.html { redirect_to post_path(@post, :anchor => 'comments') } format.atom {} format.js { render @comments } end end |
#new ⇒ Object
79 80 81 |
# File 'app/controllers/comments_controller.rb', line 79 def new @comment = Comment.new end |
#reject ⇒ Object
94 95 96 97 98 |
# File 'app/controllers/comments_controller.rb', line 94 def reject @comment = Comment.find(params[:id]) @comment.mark_as_spam! redirect_to post_path(@comment.post, :anchor => dom_id(@comment)) end |
#show ⇒ Object
83 84 85 86 |
# File 'app/controllers/comments_controller.rb', line 83 def show @comment = Comment.find(params[:id]) redirect_to post_path(@comment.post, :anchor => dom_id(@comment)) end |
#update ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/comments_controller.rb', line 60 def update @post = Post.find(params[:post_id]) @comment = Comment.find(params[:id]) if @comment.update_attributes(params[:comment]) respond_to do |format| format.html do flash[:notice] = 'Save successful!' redirect_to post_path(@post, :anchor => dom_id(@comment)) end end else render :action => 'edit' end end |