私のデータベースに配列(:vehicles)を格納しようとしています。この配列は、ユーザーがチェックボックスで選択した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)<< [:車] end' – crievino