Topic: Sortable list position not save in database with latest scriptaculous

Hi all,

I come to get some help on a weird issue ...
I created a list (ul, li) and add the following statement in my show view :

<%= sortable_element 'task_group',
    :url => {:action =>"sort", :id =>@task_group },
    :complete => visual_effect(:highlight, 'task_group')
%>

Now, if I use the scriptaculous library deliver with rails, it works but if I use the latest release of scriptaculous (1.6.5) then the list is sortable but the "position" is not save in the database ... like if sort action was never called or sort parameters were bad ...

Any idea ???

Thanks for the help !!!

Re: Sortable list position not save in database with latest scriptaculous

Perhaps the latest version of Scriptaculous sends the parameters differently. Take a look at the params hash (it is written to the development log). Please post both the params hash and your controller's sort action if you aren't able to solve it.

Railscasts - Free Ruby on Rails Screencasts

Re: Sortable list position not save in database with latest scriptaculous

Hi ryanb !

Here is what I get in the log file when using the scriptaculous version shipped with rails :
Processing TaskGroupController#sort (for 127.0.0.1 at 2006-11-22 20:29:29) [POST]
  Session ID: f68e30da240ef5fa38879f4fcde6437d
  Parameters: {"action"=>"sort", "id"=>"2", "controller"=>"task_group", "task_group"=>["7", "8", "9", "6"]}
  ^[[4;36;1mTaskGroup Load (0.000650)^[[0m   ^[[0;1mSELECT * FROM task_groups WHERE (task_groups.id = '2') LIMIT 1^[[0m
  ^[[4;35;1mTaskGroup Columns (0.000247)^[[0m   ^[[0mSHOW FIELDS FROM task_groups^[[0m
  ^[[4;36;1mTask Load (0.000403)^[[0m   ^[[0;1mSELECT * FROM tasks WHERE (tasks.task_group_id = 2) ORDER BY position ^[[0m
  ^[[4;35;1mTask Columns (0.000193)^[[0m   ^[[0mSHOW FIELDS FROM tasks^[[0m
  ^[[4;36;1mSQL (0.000069)^[[0m   ^[[0;1mBEGIN^[[0m
  ^[[4;35;1mTask Update (0.000248)^[[0m   ^[[0mUPDATE tasks SET `task_group_id` = 2, `position` = 2, `name` = 'Task 33' WHERE id = 8^[[0m
  ^[[4;36;1mSQL (0.000066)^[[0m   ^[[0;1mCOMMIT^[[0m
  ^[[4;35;1mSQL (0.000064)^[[0m   ^[[0mBEGIN^[[0m
  ^[[4;36;1mTask Update (0.000167)^[[0m   ^[[0;1mUPDATE tasks SET `task_group_id` = 2, `position` = 1, `name` = 'Task270' WHERE id = 7^[[0m
  ^[[4;35;1mSQL (0.000066)^[[0m   ^[[0mCOMMIT^[[0m
  ^[[4;36;1mSQL (0.000064)^[[0m   ^[[0;1mBEGIN^[[0m
  ^[[4;35;1mTask Update (0.000141)^[[0m   ^[[0mUPDATE tasks SET `task_group_id` = 2, `position` = 3, `name` = 'Task 12' WHERE id = 9^[[0m
  ^[[4;36;1mSQL (0.000063)^[[0m   ^[[0;1mCOMMIT^[[0m
  ^[[4;35;1mSQL (0.000063)^[[0m   ^[[0mBEGIN^[[0m
  ^[[4;36;1mTask Update (0.000255)^[[0m   ^[[0;1mUPDATE tasks SET `task_group_id` = 2, `position` = 4, `name` = 'Task 127' WHERE id = 6^[[0m
  ^[[4;35;1mSQL (0.000070)^[[0m   ^[[0mCOMMIT^[[0m
Completed in 0.01365 (73 reqs/sec) | Rendering: 0.00008 (0%) | DB: 0.00283 (20%) | 200 OK [http://localhost/task_group/sort/2]


and here is the error message I get when using the latest version (1.6.x) :



rocessing TaskGroupController#sort (for 127.0.0.1 at 2006-11-22 20:57:17) [POST]
  Session ID: f68e30da240ef5fa38879f4fcde6437d
  Parameters: {"action"=>"sort", "id"=>"2", "controller"=>"task_group", "task_group"=>["7"]}
  TaskGroup Load (0.000335)   SELECT * FROM task_groups WHERE (task_groups.id = '2') LIMIT 1
  TaskGroup Columns (0.000270)   SHOW FIELDS FROM task_groups
  Task Load (0.000437)   SELECT * FROM tasks WHERE (tasks.task_group_id = 2) ORDER BY position 
  Task Columns (0.000236)   SHOW FIELDS FROM tasks

NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.+):
    .//app/controllers/task_group_controller.rb:15:in `sort'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:110:in `method_missing'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:90:in `method_missing'
    .//app/controllers/task_group_controller.rb:14:in `sort'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in `service'
    /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
    script/server:3


Looks like this is the array passed as parameter that isn't good ...
an issue with Sortable.serialized ?

Last edited by jdelgoulet (2006-11-22 15:03:25)

Re: Sortable list position not save in database with latest scriptaculous

jdelgoulet wrote:

Looks like this is the array passed as parameter that isn't good ...
an issue with Sortable.serialized ?

Yeah, I think you're right. It probably doesn't like passing multiple form fields with the same name. You may want to try replacing the new serialize method with the old one and see if that solves your problem. Seems like a pretty big bug in scriptaculous if this is the problem.

Railscasts - Free Ruby on Rails Screencasts