title: Displaying a comment on an image
body: <p>So <a href="https://stackoverflow.com/questions/10449780/displaying-comments-under-an-image">yesterday</a> I had an issue where I couldn't display comments on my artist page from friends, I have managed to resolve this issue but now I am struggling to display comments on my images. </p>
  
  <p>All I want to do at the moment is display comments that I have input into the database manually and display them underneath my image.</p>
  
  <p>This is the model for images:</p>
  
  <pre><code>class Image &lt; ActiveRecord::Base
    has_many :publishings
    has_many :artists, :through =&gt; :publishings
    has_many :comments,:through =&gt; :friends
    has_many :comments, :as =&gt; :resource, :class_name =&gt; "Commentable"
  end
  </code></pre>
  
  <p>This is the show.html for images</p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  &lt;div id="container"&gt;
    &lt;p&gt;
      &lt;b&gt;Title:&lt;/b&gt;
      &lt;%= @image.title %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;b&gt;Filename:&lt;/b&gt;
      &lt;%= @image.filename %&gt;
      &lt;%= image_tag @image.filename %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;b&gt;Likes:&lt;/b&gt;
      &lt;span id="images_&lt;$=@image.id%&gt;_likes_count"&gt;&lt;%= @image.likes %&gt;&lt;/span&gt;
    &lt;/p&gt;
    &lt;div id="comments"&gt;
      &lt;h2&gt;Comments&lt;/h2&gt; 
      &lt;%= render :partial =&gt; "shared/comment", :collection =&gt; @image.comments%&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;%= link_to 'Like', like_image_path(@image), :method =&gt; :post %&gt; |
  &lt;%= link_to 'Edit', edit_image_path(@image) %&gt; |
  &lt;%= link_to 'Back', images_path %&gt;
  </code></pre>
  
  <p>This is the error I am receiving at the moment:</p>
  
  <pre><code>&gt; undefined method `first_name' for nil:NilClass
  
      Extracted source (around line #16):
  
  13: &lt;/p&gt;
  14: &lt;p&gt;
  15:   &lt;b&gt;First name:&lt;/b&gt;
  16:   &lt;%= @artist.first_name %&gt;
  17: &lt;/p&gt;
  18: 
  19: &lt;p&gt;
  </code></pre>
  
  <p>Application Trace</p>
  
  <pre><code>app/views/images/show.html.erb:16:in `_app_views_images_show_html_erb___1549892128_70077336775360_0'
  app/controllers/images_controller.rb:18:in `show'
  </code></pre>
  
  <p>This is the model for the friends and it displays the correct method:</p>
  
  <pre><code>class Friend &lt; ActiveRecord::Base
    has_many:friends
    has_many :artists, :through =&gt; :publishings
  
    def display_name
      "#{self.first_name} #{self.second_name}"
    end
  end
  </code></pre>