Guest User

Untitled

a guest
Apr 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. class CommentsController < ApplicationController
  2. before_filter :load_post
  3.  
  4. # GET /comments
  5. # GET /comments.xml
  6. def index
  7. @comments = @post.comments.find(:all)
  8.  
  9. respond_to do |format|
  10. format.html # index.html.erb
  11. format.xml { render :xml => @comments }
  12. end
  13. end
  14.  
  15. # GET /comments/1
  16. # GET /comments/1.xml
  17. def show
  18. @comment = @post.comments.find(params[:id])
  19.  
  20. respond_to do |format|
  21. format.html # show.html.erb
  22. format.xml { render :xml => @comment }
  23. end
  24. end
  25.  
  26. # GET /comments/new
  27. # GET /comments/new.xml
  28. def new
  29. @comment = @post.comments.build
  30.  
  31. respond_to do |format|
  32. format.html # new.html.erb
  33. format.xml { render :xml => @comment }
  34. end
  35. end
  36.  
  37. # GET /comments/1/edit
  38. def edit
  39. @comment = @post.comments.find(params[:id])
  40. end
  41.  
  42. # POST /comments
  43. # POST /comments.xml
  44. def create
  45. @comment = @post.comments.build(params[:comment])
  46.  
  47. respond_to do |format|
  48. if @comment.save
  49. flash[:notice] = 'Comment was successfully created.'
  50. format.html { redirect_to(@post) }
  51. format.xml { render :xml => @comment, :status => :created, :location => @comment }
  52. else
  53. format.html { render :action => "new" }
  54. format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
  55. end
  56. end
  57. end
  58.  
  59. # PUT /comments/1
  60. # PUT /comments/1.xml
  61. def update
  62. @comment = @post.comments.find(params[:id])
  63.  
  64. respond_to do |format|
  65. if @comment.update_attributes(params[:comment])
  66. flash[:notice] = 'Comment was successfully updated.'
  67. format.html { redirect_to([@post, @comment]) }
  68. format.xml { head :ok }
  69. else
  70. format.html { render :action => "edit" }
  71. format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
  72. end
  73. end
  74. end
  75.  
  76. # DELETE /comments/1
  77. # DELETE /comments/1.xml
  78. def destroy
  79. @comment = @post.comments.find(params[:id])
  80. @comment.destroy
  81.  
  82. respond_to do |format|
  83. format.html { redirect_to(post_comments_url(@post)) }
  84. format.xml { head :ok }
  85. end
  86. end
  87.  
  88. def load_post
  89. @post = Post.find(params[:post_id])
  90. end
  91. end
Add Comment
Please, Sign In to add comment