title: Rails 5 - Shrine issue: "undefined method `cached_image_data' for nil:NilClass"
body: <p>I've run into some issues when trying to allow the upload of an avatar with Shrine. I'm using Rails 5. I continually get the error, "undefined method `cached_image_data' for nil:NilClass". </p>
  
  <p>I've tried restarting several times, and following along with various tutorials. As far as I can tell, I am doing everything I'm meant to. ImageUploader is set, my Photo model is set etc. I've included the relevant bits of code below.</p>
  
  <p>apps/models/photo.rb:</p>
  
  <pre><code>class Photo &lt; ApplicationRecord
  
      include ImageUploader::Attachment.new(:image) 
  
  end
  </code></pre>
  
  <p>apps/uploaders/image_uploader.rb
  require "image_processing/mini_magick"</p>
  
  <pre><code>class ImageUploader &lt; Shrine
     plugin :processing
     plugin :versions, names: [:original, :thumb, :medium]
     plugin :delete_raw # delete processed files after uploading
  
  
  process(:store) do |io, context|
      original = io.download
      pipeline = ImageProcessing::MiniMagick.source(original)
      size_80 = pipeline.resize_to_limit!(80, 80)
      size_300 = pipeline.resize_to_limit!(300, 300)
      original.close!
      # return hash of 3 sizes of the same image
      { original: io, thumb: size_80, medium: size_300 }
  end
  </code></pre>
  
  <p>end</p>
  
  <p>app/views/profiles/_form.html.erb</p>
  
  <pre><code>&lt;%= form_with(model: profile, local: true) do |form| %&gt;
  
     &lt;div class="field"&gt;
       &lt;%= form.label :image %&gt;
       &lt;%= form.hidden_field :image, value: @photo.cached_image_data %&gt;
       &lt;%= form.file_field :image, id: :photo_image_data %&gt;
     &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>app/controllers/profile_controller.rb</p>
  
  <pre><code>class ProfilesController &lt; ApplicationController
    before_action :set_profile, only: [:show, :edit, :update, :destroy]
    before_action :view_own_profile, only: [:show]
  
    def show
    end
  
     private
     def set_profile
       @profile = Profile.find(params[:id])
     end
  
  def profile_params
    params.require(:profile).permit(:first_name, :last_name, :mobile, 
    :street_address, :suburb, :postcode, :country, :mobile, :image, 
    :latitude, :longitude, :user_id)
  end
  </code></pre>
  
  <p>end</p>
  
  <p>Any help at all would be greatly appreciated. Please let me know if there's any other information needed.</p>
  
  <p>Cheers,
  Gen</p>