jQuery-UI の並べ替え可能な接続リストの位置を Rails バックエンドに保存しようとしています。パラメータをデータベースに保存しようとすると、Rails Controller アクションに問題が発生します。私が得ているエラーはTypeError (can't convert Symbol into Integer):
私が送信している Ajax POST リクエストのパラメーターは次のようになります。
Activity:[{"id":"65","column":"48"},{"id":"65","column":"48"},{"id":"67","column":"48"}]
私の Rails コントローラ アクションは次のとおりです (「id」の ID でアクティビティを更新しようとしており、属性 position を「position」で更新し、day_id を「column」で更新しようとしています:
def sort
JSON.parse(params[:Activity]).each_with_index do |x, index|
id = x["id"]
position = index+1
column = x["column"]
Activity.update_all(position = position, day_id = column, id = id)
end
render nothing: true
end
ターミナルで次のエラーが表示されます。
Started POST "/trips/sort" for 10.0.2.2 at 2012-11-04 23:52:30 +0000
Processing by TripsController#sort as */*
Parameters: {"Activity"=>"[{\"id\":\"66\",\"column\":\"49\"},{\"id\":\"66\",\"column\":\"49\"},{\"id\":\"67\",\"column\":\"49\"}]"}
Completed 500 Internal Server Error in 1ms
TypeError (can't convert Symbol into Integer):
参考になる場合、これは私の jQuery AJAX 呼び出しです。
jQuery ->
$('[id*="day"]').sortable(
connectWith: ".day"
placeholder: "ui-state-highlight"
update: (event, ui) ->
neworder = new Array()
$(this).children().each ->
column = $(this).parent().attr("id").match(/\d+/)[0]
id = $(this).attr("id").match(/\d+/)[0]
neworder.push(
id: id
column: column
)
alert neworder
$.ajax
url: "sort"
type: "POST"
data: { Activity: JSON.stringify(neworder) }
).disableSelection()
私はこれに過去数時間を費やしましたが、それを理解することはできません. 時間と助けに本当に感謝しています。