Rails 5 Nested attributes "Unpermitted parameter" - Whitelisted
<p><strong>Error: Unpermitted parameter: properties</strong></p>

<p>I'm whitelisting the properties{} in the request_controller.rb 
This usually works but not this time. </p>

<p>I'm not been able to save some of the data entered in a form. The 3 fields that are not saving are coming from a dynamic form "request_type". I followed Rails Cast episode 403 for this solution, which I have working well in another project but not in this one.</p>

<p>Source: <a href="http://railscasts.com/episodes/403-dynamic-forms" rel="nofollow noreferrer">http://railscasts.com/episodes/403-dynamic-forms</a></p>

<p>Sorry if this is a duplicate question, but I've looked at several other questions and I can't pin-point what I'm doing wrong here</p>

<p>I've researched several questions here, but I'm still not able to get it to work: <br>
<a href="https://stackoverflow.com/questions/15919761/rails-4-nested-attributes-unpermitted-parameters">Rails 4 Nested Attributes Unpermitted Parameters</a> <br>
<a href="https://stackoverflow.com/questions/18474599/nested-attributes-unpermitted-parameters-rails-4">Nested attributes - Unpermitted parameters Rails 4</a></p>

<p><em>I'm omitting some stuff to make it easier to read the code. Please ask me if you need to see more.</em></p>

<p><strong>Here's the log:</strong></p>

<pre><code>Processing by RequestsController#create as HTML
  Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"8EASewOIxY58b+SU+dxd2YAfpjt38IdwNSju69RPwl/OKfx3AfmvLav79igj8CqPbDwi0eJAwojRbtm+C9F6wg==", "request"=&gt;{"name"=&gt;"asdasddaa", "due_date(1i)"=&gt;"2016", "due_date(2i)"=&gt;"9", "due_date(3i)"=&gt;"15", "user_id"=&gt;"1", "project_id"=&gt;"1", "request_type_id"=&gt;"2", "properties"=&gt;{"Name and last name"=&gt;"asdasd", "Mobile"=&gt;"asdada", "Office tel."=&gt;"asdadas"}}, "commit"=&gt;"Create Request"}
Unpermitted parameter: properties
</code></pre>

<p><strong>Update</strong></p>

<p>If I change the request_params to this:</p>

<pre><code>def request_params
  params.require(:request).permit(:name, :due_date, :group_id, :user_id, :project_id, :request_type_id, properties:{} ).tap do |whitelisted|
    whitelisted[:properties] = params[:request][:properties]
  end
end
</code></pre>

<p><strong>See:</strong> 
<em>properties:{}</em></p>

<p>I get this Error:</p>

<pre><code>Unpermitted parameters: Name and last name, Mobile, Office tel.
</code></pre>

<p><strong>request_controller.rb</strong></p>

<pre><code>  def new
    @request = Request.new
    @request_type = RequestType.find(params[:request_type_id])
    @project = @request_type.project.id
  end

  def create
    @request = Request.new(request_params)

    respond_to do |format|
      if @request.save
        format.html { redirect_to @request, notice: 'Request was successfully created.' }
        format.json { render :show, status: :created, location: @request }
      else
        format.html { render :new }
        format.json { render json: @request.errors, status: :unprocessable_entity }
      end
    end
  end

    def request_params
      params.require(:request).permit(:name, :due_date, :group_id, :user_id, :project_id, :request_type_id, :properties).tap do |whitelisted|
        whitelisted[:properties] = params[:request][:properties]

      end
    end
</code></pre>

<p><strong>request_types_controller.rb</strong></p>

<pre><code>  def new
    @request_type = RequestType.new
    @project = Project.find(params[:project])
  end

  def create
    @request_type = RequestType.new(request_type_params)

    respond_to do |format|
      if @request_type.save
        format.html { redirect_to @request_type, notice: 'Request type was successfully created.' }
        format.json { render :show, status: :created, location: @request_type }
      else
        format.html { render :new }
        format.json { render json: @request_type.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @request_type.update(request_type_params)
        format.html { redirect_to @request_type, notice: 'Request type was successfully updated.' }
        format.json { render :show, status: :ok, location: @request_type }
      else
        format.html { render :edit }
        format.json { render json: @request_type.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_request_type
      @request_type = RequestType.find(params[:id])
    end


    def request_type_params
      params.require(:request_type).permit(:name, :project_id, properties:{}, fields_attributes: [:name, :field_type, :required, :id, :_destroy])
      # params.require(:product_type).permit(:name, :product_type_id)      
    end
</code></pre>

<p><strong>models/request.rb</strong></p>

<pre><code>class Request &lt; ApplicationRecord
  belongs_to :group
  belongs_to :user
  belongs_to :project
  belongs_to :request_type
  serialize :properties, Hash
end
</code></pre>

<p><strong>models/request_type.rb</strong></p>

<pre><code>class RequestType &lt; ApplicationRecord
  belongs_to :project
  has_many :fields, class_name: "RequestField"
  accepts_nested_attributes_for :fields, allow_destroy: true
  has_many :requests

end
</code></pre>

<p><strong>models/request_field.rb</strong></p>

<pre><code>class RequestField &lt; ApplicationRecord
  belongs_to :request_type
end
</code></pre>

<p><strong>views/requests/new.html.erb</strong></p>

<pre><code>&lt;%= form_for @request do |f| %&gt;

  &lt;%= f.fields_for :properties, OpenStruct.new(@request.properties) do |builder| %&gt;
    &lt;% @request_type.fields.each do |field| %&gt;
      &lt;%= render "requests/fields/#{field.field_type}", field: field, f: builder %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;            


  &lt;div class="actions"&gt;
    &lt;%= f.submit class:"btn btn-primary" %&gt;
  &lt;/div&gt;
&lt;% end %&gt;
</code></pre>