Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <!-- Post Content -->
  2. <%= raw(@post.body) %>
  3. <%= render @post.comments %>
  4.  
  5. <hr>
  6.  
  7. <!-- Blog Comments -->
  8.  
  9. <!-- Comments Form -->
  10. <div class="well">
  11. <% if user_signed_in? %>
  12. <h4>Leave a Comment:</h4>
  13. <%= render 'comments/form' %>
  14. <% end %>
  15. </div>
  16.  
  17. <hr>
  18.  
  19. <!-- Post Content -->
  20. <%= raw(@post.body) %>
  21.  
  22.  
  23. <hr>
  24.  
  25. <!-- Blog Comments -->
  26.  
  27. <!-- Comments Form -->
  28. <div class="well">
  29. <% if user_signed_in? %>
  30. <h4>Leave a Comment:</h4>
  31. <%= render 'comments/form' %>
  32. <% end %>
  33. </div>
  34.  
  35. <hr>
  36.  
  37. <!-- Posted Comments -->
  38.  
  39.  
  40. <!-- Comment -->
  41. <%= render @post.comments %>
  42.  
  43. <%= form_for([@post,@post.comments.build]) do |f| %>
  44. <div class="form-group">
  45. <%= f.text_area :body, :class => "form-control", :rows => 3 %>
  46. </div>
  47. <%= f.submit :class => "btn btn-primary" %>
  48. <% end %>
  49.  
  50. <div class="media">
  51. <div class="media-body">
  52. <% if comment.user == current_user %>
  53. <%= link_to 'X',[comment.post,comment], method: :delete, data: { confirm: 'Are you sure?' }, class: "delete-button" %>
  54. <% end %>
  55. <h4 class="media-heading"><%= comment.user.alias %>
  56. <small><%= comment.created_at.strftime("Created on %m/%d/%Y") %></small>
  57. </h4>
  58. <%= comment.body %>
  59. </div>
  60. </div>
  61.  
  62. class CommentsController < ApplicationController
  63.  
  64. def create
  65. @post = Post.find(params[:post_id])
  66. @comment = @post.comments.create(params[:comment].permit(:body))
  67. @comment.user_id = current_user.id
  68. @comment.save
  69. redirect_to post_path(@post)
  70. end
  71.  
  72. def destroy
  73. @post = Post.find(params[:post_id])
  74. @comment = @post.comments.find(params[:id])
  75. if @comment.user_id == current_user.id
  76. @comment.destroy
  77. redirect_to post_path(@post)
  78. end
  79.  
  80. end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement