Guest User

Untitled

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