title: undefined method `image' for nil:NilClass
body: <p>I'm using paperclip and cocoon to deal with saving and showing images.</p>
  
  <p>But I'm having problems to show my picture.</p>
  
  <p>I have two models: Property and Picture. </p>
  
  <pre><code>class Property &lt; ApplicationRecord
      has_many :pictures, dependent: :destroy
      accepts_nested_attributes_for :pictures, reject_if: :all_blank,      allow_destroy: true
      enum property_type: [:Terreno, :Casa, :Apartamento]
  end
      class Picture &lt; ApplicationRecord
    belongs_to :property
  
    has_attached_file :image, styles: { medium: "300x300&gt;", thumb: "100x100&gt;" }
    validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
  end
  </code></pre>
  
  <p>And my index page</p>
  
  <pre><code>  &lt;div class="row"&gt;
    &lt;div class="col-md-8"&gt;
      &lt;% @properties.each do |property|%&gt;
        &lt;div class="panel panel-default"&gt;
          &lt;div class="panel-body"&gt;
            &lt;b&gt;Tipo: &lt;/b&gt;&lt;span&gt;&lt;%=property.property_type%&gt;&lt;/span&gt;&lt;/br&gt;
            &lt;b&gt;Nome: &lt;/b&gt;&lt;span&gt;&lt;%=property.name%&gt;&lt;/span&gt;&lt;/br&gt;
            &lt;%= image_tag property.pictures.first.image.url(:thumb) %&gt;
          &lt;/div&gt;
          &lt;div class="panel-footer"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;br&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But it keep showing in my browse: undefined method `image' for nil:NilClass in this line </p>
  
  <pre><code>&lt;%= image_tag property.pictures.first.image.url(:thumb) %&gt;
  </code></pre>
  
  <p>but in terminal it works:</p>
  
  <p><a href="https://i.stack.imgur.com/Tmczk.png" rel="nofollow noreferrer">Here is my terminal</a></p>
  
  <p>What is wrong with my code?</p>