79248855

Date: 2024-12-03 18:59:42
Score: 0.5
Natty:
Report link

As @sergio said, the ParamsWrapper maps the available attribute based on the attribute_names method. So you can change the default behavior of ParamsWrapper, using the following code:

class UsersController < ApplicationController
  before_action :set_user, only: %i[ show update destroy ]

  wrap_parameters :user, include: [:email_address, :password, :password_confirmation]

  # POST /users
  def create
    @user = User.new(user_params)

    if @user.save
      render json: @user, status: :created, location: @user
    else
      render json: @user.errors, status: :unprocessable_entity
    end
  end

  #...

  private
    #...

    # Only allow a list of trusted parameters through.
    def user_params
      params.expect(user: [ :email_address, :password, :password_confirmation ])
    end
end
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @sergio
  • Low reputation (0.5):
Posted by: raphox