ruby-rcade/RubyGameDev.com

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

Summary

Maintainability
Test Coverage
<% content_for :breadcrumbs do %>
  <ol class="breadcrumb">
    <li><%= link_to 'Posts', posts_path %></li>
    <li class="active"><%= @post.title %></li>
  </ol>
<% end %>

<div class="post">
  <h1>
    <%= @post.title %>
    <%= render 'votes/vote', post: @post %>
    <% if @post.instance_of? Guide %>
      <%= image_tag 'Guide.png', alt: 'Guides', class: 'guide-xs pull-left show', width: 25 %>
    <% end %> 
  </h1>

  <% if @post.type == "Guide" %>
    <p>
      <h4>Category: <%= @post.category.name %></h4>
    </p>
  <% end %>

  <p>
    Posted by: <%= @post.username %> on <%= @post.created_at.strftime("%m/%d/%Y") %>

    <% if policy(@post).update? %>
      <% if @post.type == "Guide" %>
        | <%= link_to 'Edit', edit_guide_path(@post) %>
      <% else %>
        | <%= link_to 'Edit', edit_post_path(@post) %>
      <% end %>
    <% else %>
        | <%= link_to 'Add Revision', new_guide_revision_path(guide_id: @post.id) %>
    <% end %>

    <% if policy(@post).destroy? %>
      | <%= link_to 'Destroy', post_path(@post), method: :delete, data: { confirm: 'Are you sure?' } %>
    <% end %>
  </p>

  <div class="body">
    <%= raw @post.body_html %>
    <% if @post.external_post? %>
      <p><%= link_to 'Visit Website', @post.source_url %></p>
    <% end %>
  </div>

  <%= render 'tags', post: @post %>

  <% unless @post.external_post? %>
    <h2>Comments</h2>
    <%= render 'comments/form' %>

    <% @post.comments.each do |comment| %>
      <%= render comment %>
    <% end %>
  <% end %>
</div>