How to remove a field from params[:something]

后端 未结 5 1209
野性不改
野性不改 2020-12-22 20:21

My registration form, which is a form for the Users model, takes a string value for company. However, I have just made a change such that users belongs_to companies. Therefo

5条回答
  •  执念已碎
    2020-12-22 21:03

    The correct way to achieve this is using strong_params

    class UsersController < ApplicationController
      def create
        @user = User.new(user_params)
      end
    
      private
    
      def user_params
        params.require(:user).permit(:name, :age)
      end
    end
    

    This way you have more control over which params should be passed to model

提交回复
热议问题