title: Problems with adding images to user
body: <p>When I push submit button in _form, Image should be created and linked to the user, but something went wrong. I use the same Image model for Ads and there almost the same code works right. Maybe the problem can somehow be connected with the inconsistency of devise user controllers and my user controller? </p>
  
  <p><strong>Users controller</strong></p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :set_user, only: [:show, :edit, :update, :destroy]
  
    def index
    end
  
    def show
    end
  
    def new
      @user = User.new
      @user.images.build
    end
  
    def edit
      authorize! :update, @user
      @user.images.build
    end
  
    def create
     @user = current_user
     respond_to do |format|
       if @user.save
        format.html { redirect_to board_url }
        format.json { render :show, status: :created, location: @user }
       else
        format.html { render :new }
        format.json { render json: @user.errors, status: :unprocessable_entity}
       end
     end
   end
  
  def update
    respond_to do |format|
     if @user.update(user_params)
       format.html { redirect_to board_url }
       format.json { render :show, status: :ok, location: @user }
     else
       format.html { render :edit }
       format.json { render json: @user.errors, status: :unprocessable_entity}
     end
    end
  end
  
  def destroy
    authorize! :update, @user
    @user.destroy
    respond_to do |format|
      format.html { redirect_to board_url }
      format.json { head :no_content }
    end
  end
  
  private
    def set_user
      @user = User.find(params[:id])
    end
  
    def user_params
      params.require(:user).permit(:email, images_attributes: [:id, :name])
    end
  end
  </code></pre>
  
  <p><strong>_form</strong></p>
  
  <pre><code>&lt;%= form_with(model: user, local: true) do |form| %&gt;
   &lt;%= form.fields_for :images do |image|  %&gt;
    &lt;div class="image_fields"&gt;
     &lt;div class="field"&gt;
      &lt;%= image.label t('.img_name') %&gt;&lt;br&gt;
      &lt;%= image.text_field :name %&gt;
     &lt;/div&gt;
    &lt;/div&gt;
   &lt;% end %&gt;
  
   &lt;div class="actions"&gt;
    &lt;%= form.submit %&gt;
   &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>class Image</strong></p>
  
  <pre><code>class Image &lt; ApplicationRecord
   belongs_to :ad
   belongs_to :user
   validates :name, presence: true
   ...
  </code></pre>
  
  <p><strong>class User</strong></p>
  
  <pre><code>class User &lt; ApplicationRecord
    has_many :ads
    has_many :images, dependent: :destroy
     accepts_nested_attributes_for :images,
                                  reject_if: proc { |attributes| attributes['name'].blank? },
                                  allow_destroy: true
  
     devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
  end
  </code></pre>
  
  <p><strong>Migrations</strong></p>
  
  <pre><code>class AddUserIdToImages &lt; ActiveRecord::Migration[5.1]
     def change
       add_column :images, :user_id, :integer
     end
  end
  
  class CreateImages &lt; ActiveRecord::Migration[5.1]
     def change
       create_table :images do |t|
         t.string :name
         t.references :ad, foreign_key: true
  
         t.timestamps
       end
     end 
  end
  </code></pre>