title: Rails 4 save strong parameters array
body: <p>I'm trying to do a post request to save JSON in my database.  Here's how the JSON data looks like in my rails console:</p>
  
  <pre><code>Parameters: {
  "name"=&gt;"Keyboard tutorial", "description"=&gt;"keyboard description", "category"=&gt;"Keyboards", "picture"=&gt;"keyboards.jpg",
  "lessons_attributes"=&gt;[
  {"name"=&gt;"lesson 1", "category"=&gt;"Content", "body"=&gt;"lesson body"},{"name"=&gt;"lesson 2", "category"=&gt;"Video", "body"=&gt;"link"}
  ],
  "tutorial"=&gt;{"name"=&gt;"Keyboard tutorial", "description"=&gt;"keyboard description", "category"=&gt;"Keyboards", "picture"=&gt;"keyboards.jpg"}
  }
  </code></pre>
  
  <p>So I'm trying to save each item in the lessons_attributes array into the Lesson database.</p>
  
  <p>Here's my create action. It's saving the other stuff, just not the lesson_attributes...</p>
  
  <pre><code>    def create
          @tutorial = Tutorial.new(tutorials_params)
  
          if @tutorial.save
              params.permit(lessons_attributes: [:name, :category, :body]).each do |lesson_params|
                  @tutorial.lessons &lt;&lt; Lesson.create(lesson_params)
              end                
              redirect_to tutorials_path
          else
              render 'new'
          end
      end  
  </code></pre>
  
  <p>Models</p>
  
  <pre><code>        class Lesson &lt; ActiveRecord::Base
              belongs_to :tutorial
          end
          class Tutorial &lt; ActiveRecord::Base
              has_many :lessons
          end
  </code></pre>