이 강한 매개 변수를 사용하여 레일에 의한, Strong Parameters를 참조하십시오. 필자는 대답 모든 화이트리스트 및 매개 변수의 블랙리스트는, 레일 반대를 수행 필요로하는 다른 플랫폼과는 달리
의 하단에 강한 매개 변수 섹션을 붙여. 모든 것이 블랙리스트에 올라 있으므로 대량 할당을 통해 허용하려는 매개 변수를 허용해야합니다. 객체를 저장하려고하고 특정 PARAM을 허용하지 않은 경우 따라서
왜, 당신은 "허가되지 않은 매개 변수를"볼 로그/콘솔.
허용하려는 허용 및 허용 목록 매개 변수를 통해 저장/업데이트 작업을 수행하는 것이 가장 좋습니다.
강한 매개 변수 강력한 매개 변수와
는, 액션 컨트롤러 매개 변수가 허용 된 때까지 활성 모델 질량 할당에 사용하는 것은 금지된다. 즉, 대량 업데이트를 허용 할 수있는 속성에 대해 의식적으로 선택해야하므로 노출되어서는 안되는 것을 우발적으로 노출시키지 않습니다. 필요없고 노력 400 잘못된 요청으로 끝내고 소정 레이즈/복구 흐름으로 흐르는 또한
은 파라미터로 표시 될 수있다.
class PeopleController < ActionController::Base
# This will raise an ActiveModel::ForbiddenAttributes exception
# because it's using mass assignment without an explicit permit
# step.
def create
Person.create(params[:person])
end
# This will pass with flying colors as long as there's a person key
# in the parameters, otherwise it'll raise a
# ActionController::ParameterMissing exception, which will get
# caught by ActionController::Base and turned into that 400 Bad
# Request reply.
def update
person = current_account.people.find(params[:id])
person.update!(person_params)
redirect_to person
end
private
# Using a private method to encapsulate the permissible parameters
# is just a good pattern since you'll be able to reuse the same
# permit list between create and update. Also, you can specialize
# this method with per-user checking of permissible attributes.
def person_params
params.require(:person).permit(:name, :age)
end
end
아이디어는 당신이 사용하는 것이'params.require', 다음 오류 https://github.com/rails/strong_parameters#handling-of-unpermitted-keys을 처리 할 수있다 – juanpastas
당신이 언급하는 옵션입니다 또한 유효하지만 처음에는 params.require가 더 짧은 코드를 생성 할 수 있습니다. 아마도 ... – juanpastas