Rails file upload w/ Paperclip and Polymorphic assocations
<p>I am working on a rails app w/ locations, gyms, users, and images. All of these share images, so instead of doing image upload seperately per model, I liked the solution expressed <a href="https://stackoverflow.com/questions/19279553/multiple-images-for-multiple-models-paperclip-rails">here</a> and wanted to recreate it. </p>

<p>Right now my models look like this</p>

<pre><code>class Picture &lt; ActiveRecord::Base
  belongs_to :imageable, polymorphic: true
  has_attached_file :image, style: { small: '64x64', medium: '100x100', large: '200x200' }
  validates_attachment :image, presence: true, content_type: { content_type: /\Aimage\/.*\Z/ }, 
                                                size: { in: 0..5.megabytes }
end

class Location &lt; ActiveRecord::Base
  geocoded_by :county_name
  after_validation :geocode

  has_many :pictures, as: :imageable
  accepts_nested_attributes_for :pictures #added, not sure if needed or not
end
</code></pre>

<p>and here is the locations controller. My biggest concern with the controller is if I'm handling the nested params</p>

<pre><code>class Admin::LocationsController &lt; ApplicationController
  before_action :authorize_admin!

  def new
    @location = Location.new
    @location.pictures.build
  end

  def create
    @location = Location.new(location_params)
    if @location.save
      flash[:success] = 'Location created!'
      redirect_to admin_location_path(@location)
    else
      render 'new'
    end
  end
  ...
  private
  def location_params
    params.require(:location).permit(:county_name, :description,
                                picture_attributes: [:location_id, :id, :image] )
  end
end
</code></pre>

<p>and my view</p>

<pre><code>&lt;section class="new-product"&gt;
  &lt;div class="container"&gt;
    &lt;div class="row white_panel"&gt;
      &lt;div class="col-lg-12"&gt;
                &lt;h2 class="text-center"&gt;Add New Location&lt;/h2&gt;
                &lt;hr&gt;
                &lt;%= form_for([:admin, Location.new], html: { multipart: true, class: 'form-horizontal' }) do |f| %&gt;
                  &lt;%= render 'shared/error_messages', object: f.object %&gt;
                  &lt;div class="form-group"&gt;
                      &lt;%= f.label :county_name %&gt;&lt;br&gt;
                      &lt;%= f.text_field :county_name, class: 'form-control' %&gt;&lt;br&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group"&gt;  
                      &lt;%= f.label :description %&gt;&lt;br&gt;
                      &lt;%= f.text_area :description, class: 'form-control' %&gt;&lt;br&gt;
                    &lt;/div&gt;
                  &lt;p&gt;Upload Picture&lt;/p&gt;
                  &lt;%= f.fields_for :picture, Picture.new do |image_upload| %&gt; 
                    &lt;%= image_upload.file_field :image, style: 'padding-bottom: 25px;' %&gt;
                  &lt;% end %&gt;
                  &lt;%= f.submit 'Go!', class: 'btn btn-gen np' %&gt;
                &lt;% end %&gt; 
            &lt;/div&gt;  
        &lt;/div&gt;  
    &lt;/div&gt;  
&lt;/section&gt;
</code></pre>

<p>right now, I'm not getting any errors. The location is made just fine, but nothing is happening to the picture table. It's just returning nil. </p>

<p>Does anyone see what I'm doing wrong with this? I have seen some resources for how to do this, but it seems like it's normally with old versions. </p>

<p>If it helps anyone I'm using <br>
<code>rails 4.2.6</code> <br>
<code>ruby 2.2.2p95</code> <br>
<code>paperclip 4.3.6</code> <br></p>

<p>any help at all about how to handle these relationships would be much appreciated :)</p>