title: How to modify params before creating an object
body: <p>I'm using nested attributes to create a <code>Photo</code> and a <code>Comment</code> object. I would like to set the author on the comment, which is nested inside the photo.</p>
  
  <p>Here are the params:</p>
  
  <pre><code>photo: {
    file: 'hi.jpg',
    comments_params: [
      { content: "hello world!" }
    ]
  }
  </code></pre>
  
  <p>But I would like to add the author to the comment.</p>
  
  <pre><code>  # ...
    comments_params: [
      { content: "hello world!", author: current_user }
    ]
    # ...
  </code></pre>
  
  <p>What's easiest way to do this? My controller code looks like this.</p>
  
  <pre><code>@photo = Photo.new(photo_params)
  @photo.save!
  
  private
  
  def photo_params
    params.require(:photo).permit(:file, comments_attributes: [:content])
  end
  </code></pre>
  
  <p>I can do it by manipulating the params after filtering them with <code>strong_parameters</code> (pseudo-code, but the idea stands), but I would rather not.</p>
  
  <pre><code>photo_params[:comments_attributes].each do |comment|
    comment[:author] = current_user
  end
  </code></pre>
  
  <p>But this feels a bit wrong.</p>