Rails ActiveAdmin에서 값을 입력하려고 하면 ActiveModel::ForbiddenAttributesError가 발생합니다.

조회수 1944회

기본적인 모델의 어드민 구현을 위해서 아래와 같이 ModelName을 수정할 수 있는 파일을 만들었습니다.

ActiveAdmin.register ModelName do
  menu priority: 2, label: 'aaa', parent: 'bbb'
end

편집 화면까지 잘 들어가 지는데 새로운 레코드를 생성하려고 하면 ActiveModel::ForbiddenAttributesError가 발생하네요.

ActiveModel::ForbiddenAttributesError /Users/@@/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activemodel-4.2.6/lib/active_model/forbidden_attributes_protection.rb:21:in sanitize_for_mass_assignment' /Users/@@/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:33:inassign_attributes'

왜 이런걸까요?

1 답변

  • 좋아요

    1

    싫어요
    채택 취소하기

    Rails 4 에서는 strong parameters를 사용하기 때문에 허용되지 않은 attribute 가 있으면 ActiveModel::ForbiddenAttributesError 가 납니다.

    그래서 ActiveAdmin에서도 permit_params을 꼭 넣어줘야 합니다.

    ActiveAdmin.register ModelName do
      permit_params : attr1, : attr2, :etc //<-- 이 줄을 넣으세요. 
    
     // attr1, attr2에 실제 사용하는 attribute 이름으로 바꿔서 넣으세요. 
    end
    
    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)