title: Unpermitted parameters for Dynamic Forms in Rails 4
body: <p>I'm new to Rails and built something based on this</p>
  
  <p><a href="http://railscasts.com/episodes/403-dynamic-forms" rel="nofollow noreferrer">http://railscasts.com/episodes/403-dynamic-forms</a></p>
  
  <p>but I have a problem with storing data in the additional fields...
  I have a ProductType object that has many ProductField objects. The ProductField object also belongs to a ProductType and Product object belongs to a ProductType. </p>
  
  <p>So,new dynamic fields can easily be added via the constructor ProductType, but when I try to set data in this fields via Product controller nothing happens.</p>
  
  <p>I am sure that problem is related to use strong parameters, but fix described <a href="https://stackoverflow.com/questions/17569999/unpermitted-parameters-for-double-nested-models-in-rails-4">here</a> and <a href="https://stackoverflow.com/questions/15919761/rails-4-nested-attributes-unpermitted-parameters">here</a> did't help.</p>
  
  <p><strong>product.rb</strong></p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
      belongs_to :product_type
      serialize :properties, Hash
  end
  </code></pre>
  
  <p><strong>product_type.rb</strong></p>
  
  <pre><code>class ProductType &lt; ActiveRecord::Base
      has_many :fields, class_name: "ProductField"
      accepts_nested_attributes_for :fields, allow_destroy: true
  end
  </code></pre>
  
  <p><strong>product_field.rb</strong></p>
  
  <pre><code>class ProductField &lt; ActiveRecord::Base
      belongs_to :product_type
  end
  </code></pre>
  
  <p><strong>products_controller.rb</strong></p>
  
  <pre><code>class ProductsController &lt; ApplicationController
      def new
      @product = Product.new(product_type_id: params[:product_type_id])
      end
      def product_params
      params.require(:product).permit(:name, :price, :product_type_id, {:properties =&gt; []})
      end
  </code></pre>
  
  <p><strong>product_type_controller.rb</strong></p>
  
  <pre><code>class ProductTypesController &lt; ApplicationController
      def product_type_params
      params.require(:product_type).permit(:name, fields_attributes: [:id, :name, :field_type, :required, :product_type_id])
      end
  </code></pre>
  
  <p>In console log:
  Unpermitted parameters: properties</p>
  
  <pre><code>Started PATCH "/products/4" for 127.0.0.1 at 2013-10-04 22:54:59 +0400
  Processing by ProductsController#update as HTML
  Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"my3ra60OUXexmmguk2eqRetizx3tWPMq04Z2PnODJMQ=", "product"=&gt;{"product_type_id"=&gt;"1", "name"=&gt;"Product1", "properties"=&gt;{"gjfghjf"=&gt;"123", "123"=&gt;[""]}, "price"=&gt;"10"}, "commit"=&gt;"Update Product", "id"=&gt;"4"}
  Product Load (0.3ms)  SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1  [["id", "4"]]
  Unpermitted parameters: properties
  </code></pre>
  
  <p>P.S: maybe someone faced a similar problem when watching a podcast?</p>