title: Rails Paperclip Gem - save parent model ID to path
body: <p>I have a model of <strong>ThreesixtyViewer</strong> which also has a nested resource of the <strong>ThreesixtyViewerImage</strong> model. An image attribute is being saved via the <a href="https://github.com/thoughtbot/paperclip" rel="nofollow noreferrer">paperclip gem</a> - but I am having issues updating the file path how it's needed.</p>
  <p>The images for each <strong>ThreesixtyViewer</strong> needs to be saved together within one directory that is associated with the specific viewer. For example:</p>
  <pre><code>/public/system/threesixty_viewer_images/12/large/filename.jpg
  </code></pre>
  <p>In this example, the <strong>12</strong> in the path would be the id of the specific threesixtyviewer - but I cannot find any examples with that functionality. If the <strong>ThreesixtyViewer</strong> had an ID of 57, then the path would look like so:</p>
  <pre><code>/public/system/threesixty_viewer_images/57/large/filename.jpg
  </code></pre>
  <p><strong>threesixty_viewer.rb</strong></p>
  <pre><code>belongs_to :article
  
  has_many :threesixty_viewer_images, dependent: :delete_all
  accepts_nested_attributes_for :threesixty_viewer_images, allow_destroy: true
  </code></pre>
  <p><strong>threesixty_viewer_image.rb</strong></p>
  <pre><code>belongs_to :threesixty_viewer
  
  has_attached_file :image, styles: { small: &quot;500x500#&quot;, large: &quot;1440x800&gt;&quot; },
    path: ':rails_root/public/system/:class/:VIEWER_ID/:size/:filename',
    url: '/system/:class/:VIEWER_ID/:size/:filename'
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
  </code></pre>
  <p>I know the :path and :url attributes need to beupdated for the has_attached_file within the <strong>threesixty_viewer_image.rb</strong> - but I am unsure as to how I can get the id for the threesixty_viewer... for now I added a :VIEWER_ID in it's place.</p>
  <p>Any help would be greatly appreciated! Thanks in advance for anyone who can lend an eye!</p>