Guest User

Untitled

a guest
Jun 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class CommentsController < ApplicationController
  2. def index
  3. @post = Post.find(params[:post_id])
  4. @comments = @post.comments
  5. end
  6.  
  7. def show
  8. @post = Post.find(params[:post_id])
  9. @comment = @post.comments.find(params[:id])
  10. end
  11.  
  12. def new
  13. @post = Post.find(params[:post_id])
  14. @comment = @post.comments.build
  15. end
  16.  
  17.  
  18. def create
  19. @post = Post.find(params[:post_id])
  20. @comment = @post.comments.build(params[:comment])
  21. if @comment.save
  22. redirect_to post_comment_url(@post,@comment)
  23. else
  24. render :action => "new"
  25. end
  26. end
  27.  
  28. def edit
  29. @post = Post.find(params[:post_id])
  30. @comment = @post.comments.find(params[:id])
  31. end
  32.  
  33. def update
  34. @post = Post.find(params[:post_id])
  35. @comment = Comment.find(params[:id])
  36. if @comment.update.attributes(params[:comment])
  37. redirect_to post_comment_url(@post, @comment)
  38. else
  39. render :action => "edit"
  40. end
  41. end
  42.  
  43. def destroy
  44. @post = Post.find(params[:post_id])
  45. @comment = Comment.find(params[:id])
  46. @comment.destroy
  47.  
  48. respond_to do |format|
  49. format.html { redirect_to post_comments_path(@post) }
  50. format.xml { head :ok }
  51. end
  52. end
  53.  
  54. end
Add Comment
Please, Sign In to add comment