title: Ruby on Rails Shrine Gem add a value to a new instance in form_for form
body: <p>I have a form_for form that is using the Shrine gem to upload an image onto my machine.  I am creating the new instance in the html file.  I am trying to set the cached_image_data for the new instance because I am getting an error when I try to create the new instance of StructureImage in the controller.  but I'm not sure how to write it.  I've included the plugin in the shrine.rb file and also the class ImageUploader.</p>
  
  <pre><code>require "image_processing/mini_magick"
  
  class ImageUploader &lt; Shrine
      include ImageProcessing::MiniMagick
      plugin :cached_attachment_data
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;%= form_for StructureImage.new(audit_structure_id: audit_structure.id),
      url: audit_photos_path(current_audit),
      html: { class: 'js-autosave-form camera gphoto', multipart: true } do |f| %&gt;
      &lt;%=f.hidden_field :image, value: self.cached_image_data %&gt;
      &lt;p style="display: block;"&gt;
      &lt;%= f.submit "Upload images",
          class: 'btn btn-primary', data: { disable_with: 'Uploading...' } %&gt;
      &lt;/p&gt;
  &lt;%- end %&gt;
  </code></pre>
  
  <hr>
  
  <p>I'm getting ["Image data Image data missing"] when I check the error messages for why it is not creating the new StructureImage.  I'm not really sure if I'm setting the value of image correctly in the form.</p>
  
  <p>Im getting this error in the browser</p>
  
  <p>undefined method `cached_image_data' for #&lt;#:0x0055e31019d770></p>
  
  <p>My shrine.rb file</p>
  
  <pre><code>require 'shrine'
  require 'shrine/storage/file_system'
  </code></pre>
  
  <h1>require 'shrine/storage/google_drive_storage'</h1>
  
  <pre><code>Shrine.storages = {
  cache: Shrine::Storage::FileSystem.new("public", prefix: 
  "uploads/cache"), # temporary
  store: Shrine::Storage::FileSystem.new("public", prefix: 
  "uploads/store"), # permanent
  }
  
  Shrine.plugin :activerecord
  Shrine.plugin :cached_attachment_data
  </code></pre>
  
  <p>Right now I tried using self.cached_image_data but I'm getting that error.  I've tried structure_image.cached_iamge_data that didn't work.  I tried to assign the param cached_image_data in the controller.  That didn't work either.</p>
  
  <p>Please help.</p>