私はこれで夢中になります。ドロップダウンボックスのあるフォームがあります
<select name="user[interest1]">
<option value="1">Something</option>
<option value="2">Another Something</option>
<option value="3">Another Something^3</option>
</select>
これを投稿すると、フィールド「interest1」の整数でユーザーモデルが更新されます。フォームを送信すると、次のエラーが表示されます。
Interest1(#70226795163000) expected, got String(#70226775629700)
Request
Parameters:
{"utf8"=>"✓",
...
"interest1"=>"3"},
"commit"=>"Update"}
わかりましたので、これは投稿されている文字列ですが、整数である必要があります。簡単だと思ったので、コントローラーでそのパラメーターをキャッチして整数にします。
params[:user][:interest1] = params[:user][:interest1].to_i
今、私はこれを取得します:
Interest1(#70226795828040) expected, got Fixnum(#70226775624220)
Request
Parameters:
{"utf8"=>"✓",
...
"interest1"=>3},
"commit"=>"Update"}
これは私が実際に期待していることですが、私のデータベースでは更新されません。私は何を間違っていますか?
助けてくれてありがとう。