데이터베이스 (: 차량)를 데이터베이스에 저장하려고합니다. 이 어레이는 사용자가 체크 박스로 선택할 수있는 3 가지 가능한 차량으로 구성됩니다.배열이 데이터베이스에 유지되지 않습니다
<% @vehicles.each_with_index do |vehicle,index| %>
<label>
<div >
<%= check_box_tag "vehicles[]", index ,class: "available" ,style: "display:none" %>
<%= vehicle %>
</div>
</label>
<%end %>
'차량'속성 유형은 '텍스트'내가 그것을 배열하기 위해이 코드를 사용 : 나는 배열에이 값을 가져옵니다 PARAMS를 보낼 경우
serialize :vehicles, Array
합니다.
"vehicles"=>["0", "1", "2"],
"commit"=>"Sign up!",
"controller"=>"registrations",
"action"=>"create"
문제는이 어레이가 저장하려고 시도 할 때 데이터베이스에 저장되지 않는다는 것입니다. 데이터베이스의 코드는 다음과 같습니다
vehicles: []
컨트롤러 코드 :
def create
@student = Student.create(student_params)
if @student.save!
redirect_to @student
else
render :new
end
end
학생 PARAMS :
def student_params
params.require(:student).permit(availabilities_attributes: [ :id, :day, :available])
end
사람이 어떻게 배열에 그 값을 얻는 아이디어가?
감사합니다. 에, vehicles: []
난 당신이 사용하고있는 고안의 버전을 잘 모르겠지만, 자신의 documentation에서 그림 : 당신의 강력한 매개 변수에
컨트롤러의 차량 배열 속성에 강력한 매개 변수를 허용 하시겠습니까? – Ren
포스트 액션 – bkunzi01
을 만들 @Ren 예, '데프 configure_permitted_parameters devise_parameter_sanitizer.for (: sign_up) << [: 자동차] bkunzi01 는'데프 @student = Student.create (student_params)를 만들 – crievino