title: Unpermitted parameters nested attributes - rails
body: <p>I'm trying to submit a form to 2 tables but somehow I got this syntax error <code>unexpected '\n'</code> at this line <code>joins: ['sources'], :landslide_id</code> and <code>found unpermitted parameter: sources</code> in landslide params. Here's all the files </p>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Landslide &lt; ApplicationRecord
    has_many :sources, dependent: :destroy
    accepts_nested_attributes_for :sources
  
  class Source &lt; ApplicationRecord
    belongs_to :landslide
  end
  </code></pre>
  
  <p><strong>landslides_controller.rb</strong></p>
  
  <pre><code>  def new
      @landslide = Landslide.new
      @landslide.sources.build
    end
  
    # POST /landslides
    def create
      @landslide = Landslide.new(landslide_params)
  
      @landslide.save
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_landslide
        render json: Landslide.find(params[:total_id]),
               joins: ['sources'], :landslide_id
      end
  
      # Only allow a trusted parameter "white list" through.
      def landslide_params
        params.require(:landslide).permit(:start_date, :continent, :country, :location, :landslide_type, :lat, :lng, :mapped, :trigger, :spatial_area, :fatalities, :injuries, :notes, sources_attributes: [ :url, :text ])
      end
  </code></pre>
  
  <p><strong>sources_controller.rb</strong></p>
  
  <pre><code>    def set_source
        @source = Source.find(params[:id])
      end
  
      # Only allow a trusted parameter "white list" through.
      def source_params
        params.require(:source).permit(:url, :text)
      end
  </code></pre>
  
  <p><strong>_form.html.haml</strong></p>
  
  <pre><code>= form_for :landslide, :url =&gt; {:controller =&gt; 'landslides', :action =&gt; 'create'} do |f|
  #something
         %fieldset
          %legend Source
          = f.fields_for :sources do |s|
            .form-group.row
              %label.col-sm-2.col-form-label{for: "textinput"}URL
              .col-sm-10
                = s.text_field :url, class: "form-control"
            .form-group.row
              %label.col-sm-2.col-form-label{for: "textinput"}Text
              .col-sm-10
                = s.text_field :text, class: "form-control"
  </code></pre>
  
  <p><strong>Request</strong></p>
  
  <pre><code>    {"utf8"=&gt;"✓",
   "authenticity_token"=&gt;"W3m2dLTGyuPCbP6+pStWDfgpIbPzGdl4tvf01vMAbyozzkimqlXH4B/RtwBcsLb+iiBqms7EHagY+Anbpo4zNg==",
   "landslide"=&gt;
    {"start_date(3i)"=&gt;"27",
     "start_date(2i)"=&gt;"4",
     "start_date(1i)"=&gt;"2017",
     "continent"=&gt;"Africa",
     "country"=&gt;"Country",
     "location"=&gt;"Location",
     "landslide_type"=&gt;"1",
     "lat"=&gt;"1",
     "lng"=&gt;"1",
     "mapped"=&gt;"False",
     "spatial_area"=&gt;"1",
     "fatalities"=&gt;"1",
     "injuries"=&gt;"1",
     "notes"=&gt;"1",
     "trigger"=&gt;"1",
     "sources"=&gt;{"url"=&gt;"url", "text"=&gt;"text"}},
   "button"=&gt;""}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/6tjkY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6tjkY.png" alt="Error screenshot"></a></p>