Guest User

Untitled

a guest
Feb 16th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. @post.destroy
  2. redirect_to posts_path
  3.  
  4. @post.comments.destroy
  5. redirect_to posts_path(@post)
  6. end
  7.  
  8. private def comment_params
  9. params.require(:comment).permit(:username, :body)
  10. end
  11. end
  12.  
  13. Rails.application.routes.draw do
  14. root 'posts#index', as:'home'
  15.  
  16. resources :posts do
  17. resources :comments
  18. end
  19. end
  20.  
  21. <h2> Редактирования коментария</h2>
  22. <%= form_for :post, html: {multipart: true}, url: post_path(@post), method: :patch do |f| %>
  23. <% if @post.errors.any? %>
  24. <% @post.errors.full_messages.each do |msg| %>
  25. <div class="alert alert-danger"> <%=msg %></div>
  26. <%end%>
  27. <%end%>
  28. <p>
  29. Названия<br>
  30. <%= f.text_field(:title) %>
  31. </p>
  32. <p>
  33. Текст статьи<br>
  34. <%= f.text_area(:body) %>
  35. </p>
  36. <p>
  37. <%= f.file_field :image %>
  38. </p>
  39. <p>
  40. <%=f.submit "Сохранить", class: 'btn btn-success' %>
  41. </p>
  42. <% end %>
  43.  
  44. <h1><%=@post.title %> </h1>
  45. <p><%=@post.body %></p>
  46. <p>
  47. <%= image_tag @post.image.url(:thumb), class: 'img-show' if @post.image? %>
  48. </p>
  49. <hr>
  50. <%= link_to "Редактировать", edit_post_path(@post), :class=> 'btn btn-warning' %>
  51. <%= link_to "Удалить пост", post_path(@post), method: :delete, data: {confirm:"Вы хотите удалить статью ?"}, :class => 'btn btn-danger'%>
  52. <h2>Вcе коментарии</h2>
  53. <% @post.comments.each do |comments| %>
  54. <div class="alert alert-light">
  55. <p><strong><%=comments.username%></strong>: <%=comments.body%></p>
  56. </div>
  57. <% end %>
  58. <h2>Коментарии</h2>
  59. <%=form_for([@post, @post.comments.build]) do |f| %>
  60. <p>
  61. Пользователь<br>
  62. <%=f.text_field(:username)%>
  63. </p>
  64.  
  65. <p>
  66. Текст комментария<br>
  67. <%= f.text_area(:body)%>
  68. </p>
  69.  
  70. <p>
  71. <%= f.submit("Добавить Коментарий")%>
  72. </p>
  73. <% end %>
  74. <%= link_to "Удалить Комент ", post_path(@post.comments), method: :delete, data: {confirm:"Вы хотите удалить?"}, :class => 'btn btn-danger'%>
Add Comment
Please, Sign In to add comment