Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. resources :posts do
  2. resources :comments
  3. end
  4.  
  5. <p><%= @post.title %></p>
  6.  
  7. <h2>Comments:</h2>
  8. <div id='com'>
  9. <%= render @post.comments %>
  10. </div>
  11.  
  12. <h2>Add a comment:</h2>
  13. <%= render "comments/form" %>
  14.  
  15. <p>
  16. <strong>Commenter:</strong>
  17. <%= comment.commenter %>
  18. </p>
  19. <p>
  20. <strong>Comment:</strong>
  21. <%= comment.body %>
  22. </p>
  23. <%= link_to "Del", [comment.post, comment], :confirm => 'Are you sure?', :method => :delete %>
  24. <hr>
  25.  
  26. <%= form_for([@post, @post.comments.build], remote: true) do |f| %>
  27. .
  28. .
  29. .
  30.  
  31. class CommentsController < ApplicationController
  32.  
  33. def create
  34. @post = Post.find(params[:post_id])
  35. @comment = @post.comments.create(params[:comment])
  36.  
  37. respond_to do |format|
  38. format.html { redirect_to post_path(@post) }
  39. format.js
  40. end
  41. end
  42.  
  43. $('#com').html("<%=j render @post.comments %>");
  44.  
  45. <%= javascript_include_tag 'application' %>
  46.  
  47. //= require jquery
  48. //= require jquery_ujs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement