2016-10-26 3 views
1

한 양식에서 동일한 모델의 여러 개체를 만들려고합니다. 내 create 방법으로 얻을 PARAMS는 다음과 같다 :한 양식에서 여러 개체를 만들기위한 강력한 매개 변수를 전달합니다.

<ActionController::Parameters {"objects"=> <ActionController::Parameters { 
    "0"=>{priority"=>"24", "style"=>"three_pictures"}, 
    "1"=>{"priority"=>"24", "style"=>"three_pictures"}, 
    "2"=>{"priority"=>"24", "style"=>"three_pictures"} 
} permitted: false>}permitted: false> 

나는이 경우 strong params 사용에 대한 혼란 스러워요.

def create 
    params[:objects].each do |index, object| 
    Object.create(object.permit(:priority, :style)) 
    end 
    ... 
end 

이 작동하지만,이 작업을 수행하는 올바른 방법처럼 보이지 않는 : 내 create 방법은 다음과 같습니다. 어떻게해야합니까?

+0

대량 할당 보안을 우회하지 않으려는 경우 올바른 방법이라고 생각합니다. –

답변

0

여기 좀 더 자세한 정보가 필요하다고 생각합니다. 나는 한 번에 다른 개체의는 보통 chield을 1 개 이상의 레코드를 작성하고 광산이

# Never trust parameters from the scary internet, only allow the white list through. 
def family_params 
    params.require(:family).permit(:name, users_attributes: [ :name, :email ]) 
end 

처럼 보이는 때 난이 도움이되기를 바랍니다.

해피 해킹 :)

관련 문제