title: Creating multiple objects from a post array
body: <p>I'm doing a small project to learn RoR and am stuck on a problem. I want to send a JSON array with objects to a POST request and create an object for each of the array elements, while also only permitting a set of parameters. Here's what it looks like in code:</p>
  
  <pre><code>class BodyPartsController &lt; ApplicationController
    before_action :check_admin_rights, only: [:create]
  
    def create    
      BodyPart.create!(body_parts_params)
      json_response(BodyPart.all)
    end
  
    def index 
      json_response(BodyPart.all)
    end
  
    private 
  
      def body_parts_params
        params.permit(:name, :image_url)
      end
  end
  </code></pre>
  
  <p>This is a sample request body:</p>
  
  <pre><code>[
      {
          "name" : "Abs",
          "image_url" : ""
      },
      {
          "name" : "Arms",
          "image_url" : ""
      }
  ]
  </code></pre>
  
  <p>The issue is how to setup <code>body_parts_params</code> so that I can only permit <code>name</code> and <code>image_url</code>. I know I can do something like: </p>
  
  <pre><code>  def create    
      params.each do |body_part| 
        BodyPart.create!(name: body_part[:name], image_url: body_part[:image_url])
      end
      json_response(BodyPart.all)
    end
  </code></pre>
  
  <p>but as I said, I want to make sure only the two parameters are permitted. Is there any way to do it?</p>