title: Rails activeadmin save data in associated table
body: <p>I have one table for Products and the product can either be in the interior or exterior or both. So I created another table to save the Products location. Now when admin adds the product I have provided the option to select the location(s) the product can be in, but when it is posted the code says the field can't be blank because of the validation. I am not sure what I am missing or the approach is wrong.</p>
  
  <p><strong>The product model:</strong></p>
  
  <pre><code>class Product &lt; ApplicationRecord
    validates :name, presence: true      
  
    has_many :product_locations
  
    accepts_nested_attributes_for :product_locations
  end
  </code></pre>
  
  <p><strong>The product location model:</strong></p>
  
  <pre><code>class ProductLocation &lt; ApplicationRecord
  
    enum locations: [:exterior, :interior]
  
    validates :location, presence: true
    validates :product_id, presence: true
  
    belongs_to :product
  end
  </code></pre>
  
  <p><strong>The ActiveAdmin file for Product:</strong></p>
  
  <pre><code>ActiveAdmin.register Product do
  
    permit_params :name, product_locations_attributes: {}
  
    actions :all, except: [:show, :destroy]
  
    filter :name
  
    index do        
      column 'Product Name',  :name
      actions
    end
  
    form do |f|
      f.semantic_errors *f.object.errors.keys
  
      f.inputs "Products" do
        f.input :name          
      end
  
      f.has_many :product_locations do |location|
        location.inputs "Locations" do
          location.input :location, as: :select, multiple: true, collection: ProductLocation.locations.keys
        end
      end
  
      f.actions
    end
  
    controller do
      def scoped_collection
        Product.where(user_id: nil)
      end
    end
  
  end
  </code></pre>
  
  <p>I get a multi-select for the locations which has "Interior" and "Exterior" for selection, but it says the field can't be blank when I select the location and submit the form</p>
  
  <p>The error on save click I get is: </p>
  
  <blockquote>
    <p>Location can't be blank</p>
  </blockquote>
  
  <p>The params that get posted are:</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "product"=&gt;{"name"=&gt;"Test Product", "product_locations_attributes"=&gt;{"0"=&gt;{"location"=&gt;["0", "1"]}}}, "commit"=&gt;"Create Product"}
  </code></pre>