0
試圖通過gette()
或者我認爲多數民衆贊成在我想要的。我選擇的每一行,並改變它的Sort.sortorder到數組值,所以我想用racksh與西納特拉迭代Datamapper得到更新單獨的行
sqlite> select * from sorts;
515|1|2012-02-24T14:44:07-05:00
516|2|2012-02-24T14:44:07-05:00
517|3|2012-02-24T14:44:07-05:00
518|4|2012-02-24T14:44:07-05:00
sqlite>
測試代碼歸結爲迄今
adkjsd = [1,2,3,4]
adkjsd.each do |jk|
puts jk + 1
Sort.all.update(:sortorder => jk) # true updates all rows to 4 the last in the array
Sort.get(516).update(:sortorder => 0) # only updates that row
end
Sort.all.update(:sortorder => jk) # true updates all rows to 4 the last in the array
#output
sqlite> select * from sorts;
515|4|2012-02-24T14:44:07-05:00
516|4|2012-02-24T14:44:07-05:00
517|4|2012-02-24T14:44:07-05:00
518|4|2012-02-24T14:44:07-05:00
sqlite>
Sort.get(516).update(:sortorder => 0) # only updates that row
#output
sqlite> select * from sorts;
515|4|2012-02-24T14:44:07-05:00
516|0|2012-02-24T14:47:03-05:00
517|4|2012-02-24T14:44:07-05:00
518|4|2012-02-24T14:44:07-05:00
sqlite>
!!!!!你贏得了一百萬的互聯網!謝謝!這是一個學習冒險,在我的問題堆棧中與前面的問題結合起來。 http://stackoverflow.com/questions/9425096/sinatra-ruby-iterate-over-an-array-in-a-hash-to-send-jquery-sortable-to-database/9426068#comment11918408_9426068 再次謝謝你! – tripdragon 2012-02-24 20:42:53
不客氣:) – 2012-02-24 20:46:08