Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <h1>Listing posts</h1>
  2. <% if user_signed_in? %>
  3. <div class="field">
  4. <%= link_to 'Create a New Post', new_post_path, :class => "btn btn-success btn-sm" %>
  5. </div>
  6. <% end %>
  7.  
  8. <% @posts.each do |post| %>
  9. <div class="post thumbnail">
  10. <h3><%= post.name %></h3>
  11. <div><h5>edit by <%= post.post_user_name %></h5></div>
  12. <div><%= (post.descriptopm).html_safe %></div>
  13.  
  14. <% if user_signed_in? %>
  15. <div class="bottom-bottoms">
  16. <%= link_to 'Display', post, :class => "btn btn-info btn-xs" %>
  17. <%= link_to 'Edit', edit_post_path(post), :class => "btn btn-info btn-xs" %>
  18. <%= link_to 'Delete', post, method: :delete, data: { confirm: 'Are you sure?' }, :class => "btn btn-info btn-xs" %>
  19. </div>
  20. <% end %>
  21.  
  22. <h3>Comments</h3>
  23. <% post.comments.each do |comment| %>
  24. <div>
  25. <p><strong><%= comment.user_name %></strong> : <%= (comment.body).html_safe %></p>
  26. </div>
  27. <% end %>
  28.  
  29. <%= bootstrap_form_for(@comment) do |f| %>
  30. <% if @comment.errors.any? %>
  31. <div id="error_explanation">
  32. <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
  33.  
  34. <ul>
  35. <% @comment.errors.full_messages.each do |msg| %>
  36. <li><%= msg %></li>
  37. <% end %>
  38. </ul>
  39. </div>
  40. <% end %>
  41.  
  42. <% if user_signed_in? %>
  43. <div class="field">
  44. <%= f.text_field :user_name, value: current_user.username, :disabled => true %>
  45. </div>
  46. <div class="field">
  47. <%= f.text_area :body %>
  48. </div>
  49. <%= f.hidden_field :post_id, value: post.id %>
  50. <div class="actions">
  51. <%= f.submit %>
  52. </div>
  53. <% end %>
  54.  
  55. <% end %>
  56.  
  57. </div>
  58. <% end %>
  59.  
  60. <div class="field">
  61. <%= f.text_field :post_user_name, value: current_user.username, :disabled => true, label: "Your Name" %>
  62. </div>
  63.  
  64. def post_params
  65. params.require(:post).permit(:name, :post_user_name, :descriptopm)
  66. end
  67.  
  68. def comment_params
  69. params.require(:comment).permit(:user_name, :body, :post_id)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement