Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Post Content -->
- <%= raw(@post.body) %>
- <%= render @post.comments %>
- <hr>
- <!-- Blog Comments -->
- <!-- Comments Form -->
- <div class="well">
- <% if user_signed_in? %>
- <h4>Leave a Comment:</h4>
- <%= render 'comments/form' %>
- <% end %>
- </div>
- <hr>
- <!-- Post Content -->
- <%= raw(@post.body) %>
- <hr>
- <!-- Blog Comments -->
- <!-- Comments Form -->
- <div class="well">
- <% if user_signed_in? %>
- <h4>Leave a Comment:</h4>
- <%= render 'comments/form' %>
- <% end %>
- </div>
- <hr>
- <!-- Posted Comments -->
- <!-- Comment -->
- <%= render @post.comments %>
- <%= form_for([@post,@post.comments.build]) do |f| %>
- <div class="form-group">
- <%= f.text_area :body, :class => "form-control", :rows => 3 %>
- </div>
- <%= f.submit :class => "btn btn-primary" %>
- <% end %>
- <div class="media">
- <div class="media-body">
- <% if comment.user == current_user %>
- <%= link_to 'X',[comment.post,comment], method: :delete, data: { confirm: 'Are you sure?' }, class: "delete-button" %>
- <% end %>
- <h4 class="media-heading"><%= comment.user.alias %>
- <small><%= comment.created_at.strftime("Created on %m/%d/%Y") %></small>
- </h4>
- <%= comment.body %>
- </div>
- </div>
- class CommentsController < ApplicationController
- def create
- @post = Post.find(params[:post_id])
- @comment = @post.comments.create(params[:comment].permit(:body))
- @comment.user_id = current_user.id
- @comment.save
- redirect_to post_path(@post)
- end
- def destroy
- @post = Post.find(params[:post_id])
- @comment = @post.comments.find(params[:id])
- if @comment.user_id == current_user.id
- @comment.destroy
- redirect_to post_path(@post)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement