Trying to update a Jquery Sortable list to the database

138 views
Skip to first unread message

tripdragon

unread,
Feb 23, 2012, 2:21:53 AM2/23/12
to sinatrarb
Using Dattamapper, SQLite

Using Jquery UI's Sortable i'm trying to get the right command syntax
to update the database.
It does not have a url id, or I dont know enough yet to get one via
ajax.
Perhaps I am doing this completly wrong. I could get it to create new
rows on each sortable change. But update requires an :id
If I change a line to u = Sort.update (:sortorder => 1)
I can see that I am sending something. Now how do I get the data from
the sorting. Hmmmm sooo very close.


var foo = $( "#sortable" ).sortable({
update: function(event, ui){
$.ajax({
type: 'post',
data: foo.sortable("serialize"),
dataType: 'script',
url: '/sort'
});
}
});


#app.rb
post '/sort' do
u = Sort.update (:sortorder => 1)
u.updated_at = Time.now
u.save
end

DAZ

unread,
Feb 24, 2012, 2:20:30 AM2/24/12
to sinatrarb
Can we see more of your code? What is the model you are trying to
update and how do you actually want it sorted?

DAZ

tripdragon

unread,
Feb 24, 2012, 12:00:30 PM2/24/12
to sinatrarb
> Can we see more of your code? What is the model you are trying to
> update and how do you actually want it sorted?
>
> DAZ

I pasted the bare app with a few puts in the code still as I dig
through it and test.
http://pastebin.com/VAcsZjNs
Its end goal is to update the database of the sortment from jQuery UI
Sortables

Currently I have it sending the same id to each row instead of the
assortment.
sqlite> select * from sorts;
491|2|2012-02-24T11:44:19-05:00
492|2|2012-02-24T11:44:19-05:00
493|2|2012-02-24T11:44:19-05:00
494|2|2012-02-24T11:44:19-05:00

when I want for example
sqlite> select * from sorts;
491|4|2012-02-24T11:44:19-05:00
492|1|2012-02-24T11:44:19-05:00
493|2|2012-02-24T11:44:19-05:00
494|3|2012-02-24T11:44:19-05:00

I was working with two others at stackoverflow yesterday to get one
portion of the itteration working
http://stackoverflow.com/questions/9425096/sinatra-ruby-iterate-over-an-array-in-a-hash-to-send-jquery-sortable-to-database/9426068#comment11918408_9426068
However that's a mess right now.

Here are two links to Rails versions of the Sortable I can not seem to
get translated just yet
http://practiceovertheory.com/blog/2009/08/07/sortable-lists-with-jquery-in-rails/
http://webtempest.com/sortable-list-in-ruby-on-rails-3-almost-unobtrusive-jquery/

Thank you for your help. I can hop in the irc channel if that helps.
It was pretty quiet there yesterday for anything at all unless there's
a different channel.
Reply all
Reply to author
Forward
0 new messages