ActiveModel::ForbiddenAttributesError when creating new user

后端 未结 7 1825
礼貌的吻别
礼貌的吻别 2020-11-22 15:59

I have this model in Ruby but it throws a ActiveModel::ForbiddenAttributesError

class User < ActiveRecord::Base
  attr_accessor :password
  v         


        
7条回答
  •  臣服心动
    2020-11-22 16:39

    If using ActiveAdmin don't forget that there is also a permit_params in the model register block:

    ActiveAdmin.register Api::V1::Person do
      permit_params :name, :address, :etc
    end
    

    These need to be set along with those in the controller:

    def api_v1_person_params
      params.require(:api_v1_person).permit(:name, :address, :etc)
    end
    

    Otherwise you will get the error:

    ActiveModel::ForbiddenAttributesError
    

提交回复
热议问题