meghaniankov/acebook-catbook-inc

View on GitHub
app/views/posts/show.html.erb

Summary

Maintainability
Test Coverage
<div id='post-spacer'>
  </div>
  
  <div id='post-spacer'>
  </div>

<div id='posts'>
    <div class="card">
      <div id='top'> 
        <div id='top-left'>
          <div id='post-user'>
          <a href=<%= user_page_path(User.find(@post.user_id))%>><%= User.find(@post.user_id).email  %></a>
          </div>

          <div id='post-date'> 
          <%= @post.created_at.strftime("%m/%d/%Y, %H:%M") %>
          </div>
        </div>

        <div id='post-links'> 
          <%= link_to 'Edit', edit_post_path(@post) %>
          <%= link_to 'Delete', @post, :method => :delete %>
        </div>

      </div>

      <div id='post-message'>
        <%= simple_format(@post.message, {}, wrapper_tag: "div") %>
      </div>

      <div id='post-img'>
        <% if @post.image.attached? %>
          <%= image_tag @post.image, id: 'img' %>
        <%end%>
      </div>

      <div id='likes'>
      <% pre_like = @post.likes.find { |like| like.user_id == current_user.id }%>
        <% if pre_like %>
          <%= link_to '♥️', post_like_path(@post, pre_like), method: :delete %>
        <% else %>
          <%= link_to '♡', post_likes_path(@post), method: :post %>
        <% end %>
        <%= @post.likes.count %> <%= (@post.likes.count) == 1 ? 'Like' : 'Likes' %>
      </div>

      <div id='post-comments'>
      <% @post.comments.each do |comment| %>
        <div id='post-comment'>
            <div id='post-comment-user'>
            <a href=<%= user_page_path(User.find(comment.user_id))%>><%= User.find(comment.user_id).email  %></a>
            </div>
  
            <div id='post-comment-text'>
              <%= simple_format(comment.body, {}, wrapper_tag: "div") %>
            </div>
          </div>
      <% end %>
    </div> 
  
      <div id='add-comment-container'>
        <div id='add-comment-form'>
          <%= form_with(model: [ @post, @post.comments.build ], local: true) do |form| %>
              <%= form.label 'Add Comment' %><br>
              <%= form.text_area :body %>
            <p>
              <%= form.submit 'Save' %>
            </p>
            <% end %>
        </div>
      </div>
  
    </div>
    <div id='post-spacer'>
    </div>


</div>