title: How to set a default value for params.permit
body: <p>I want to set a default value to one of my permited parameters.</p>
  
  <p>I tried to do like they said <a href="http://api.rubyonrails.org/classes/ActionController/Parameters.html" rel="nofollow">http://api.rubyonrails.org/classes/ActionController/Parameters.html</a></p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
    def new
      @user = User.new
    end
  
    def show
     @user = current_user
    end
  
    def create
      user_params = ActionController::Parameters.new({
                                                         user: {
                                                             avatar_link: '/assets/avatar-placeholder.png'
                                                     }
                                                 })
      @user = User.new(user_params)
      if @user.save
        session[:user_id] = @user.id
        redirect_to user_path(current_user)
      else
        redirect_to new_user_path
      end
    end
  
    private
  
    def user_params
      params.require(:user).permit(:name, :username, :email, :password, :password_confirmation, :avatar_link)
    end
  end
  </code></pre>
  
  <p>But it doesn't seem to be working -- I'm getting <code>ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError)</code> because of this part:</p>
  
  <pre><code>user_params = ActionController::Parameters.new({
                                                user: {
                                                    avatar_link: '/assets/avatar-placeholder.png'
                                                }
                                            })
  </code></pre>
  
  <p>How should I set a default value for my <code>params</code>?</p>
  
  <p>UPD: I've tried to use @xlembouras solution, but now I have <code>rollback transaction</code></p>
  
  <pre><code>def user_params
    defaults = {avatar_link: '/assets/avatar-placeholder.png'}
    params.require(:user).permit(:name, :username, :email, :password, :password_confirmation, :avatar_link).reverse_merge!(defaults)
    puts params
  end
  </code></pre>
  
  <p>models/user.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    before_save { self.email = email.downcase }
    has_secure_password
    validates_confirmation_of :password
    has_many :projects
  
    validates :name, presence: true, length: {maximum: 50}
    validates :username, presence: true, uniqueness: { case_sensitive: false }, length: {maximum: 50}
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, presence: true, format: {with: VALID_EMAIL_REGEX}, uniqueness: { case_sensitive: false }
    validates :password, presence: true, length: {minimum: 6}
    validates :password_confirmation, presence: true
  end
  </code></pre>