Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails3 (with Ruby 1.9.1) problem when sorting a list

#4267

Hi,

Here is a sample of the list HTML:

<ul id="sort"> 
   <li id='menu_item_1'>home</li> 
   <li id='menu_item_3'>info</li> 
   <li id='menu_item_2'>portfolio</li>
</ul>

Here is the javascript from my application.js that handles the sorting and handles the request:

$(function() {
    $("#sort").sortable({
        update : function (event, ui) {
        $.ajax({
            type: "PUT",
        url: "/pages",
        data: $(this).sortable("serialize")
        });
    }
    });
});

Now here is my problem. when I use 1.8.7 with RVM there is no problem. When I drag an item from the list around I get a nice PUT request to my controller. Here is some output in the console:

Started PUT "/pages" for 127.0.0.1 at 2010-03-25 08:47:33
  Processing by PagesController#update as */*
  Parameters: {"menu_item"=>[{"2"=>nil}, {"1"=>nil}, {"3"=>nil}]}

But when I switch with RVM to Ruby 1.9.1 and change nothing in the code, I get the following exception in the console:

Started PUT "/pages" for 127.0.0.1 at 2010-03-25 08:44:09

NoMethodError (undefined method `each' for "3":String):

Rendered /Users/jelle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/jelle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.9ms)
Rendered /Users/jelle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within /Users/jelle/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta/lib/action_dispatch/middleware/templates/rescues/layout.erb (17.6ms)

No other trace is provided... So very hard for me to debug.

What I do know is that the exception that is raised is very logic because in Ruby 1.9 the String class isn't an enumerator so it loses the .each method. (I wrote an article in my blog).

Hope someone can help me with this bug, or at least point out where I have to look to create a patch :)

Thnx in advance!

Jelle
www.fousa.be

Reported by Jelle Vandebeeck · March 25th, 2010 @ 08:17 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • Tag changed from rails 3.0 beta, exception, logging, rails3, ruby1.9 to exception, logging, rails3, ruby1.9
    • State changed from new to incomplete

    Can you show me your controller code?

    March 27th, 2010 @ 07:57 AM

  2. Jelle Vandebeeck
    Jelle Vandebeeck

    Here is my controller code.

    class PagesController < ApplicationController
      def show
        # returns all the menu items to construct the list
        @pages = Page.in_menu
      end
    
      def update
        Page.order!(params[:menu_item])
        render :nothing => true
      end
    end
    

    March 27th, 2010 @ 08:45 AM

  3. Evan Owen
    Evan Owen

    +1

    I'm having exactly the same issue as Jelle. The serialized parameters sent from jQuery look like "item[]=53&item[]=4" ... etc. Was working before, now its not.

    It seems like this is an issue with deserializing parameters having certain structures.

    May 3rd, 2010 @ 06:11 PM

  4. xds2000
    xds2000
    • Importance changed from to Low

    just as We recommend Ruby 1.8.7 or Ruby 1.9.2 for use with Rails.so dont use 1.9.1

    September 12th, 2010 @ 01:36 AM

  5. Rohit Arondekar
    Rohit Arondekar
    • State changed from incomplete to invalid

    Ruby 1.9.1 is not supported by Rails 3. Can you reproduce this issue on 1.8.7 or 1.9.2?

    Closing ticket for now but if the issue happens on the supported rubies, leave a comment and I'll reopen.

    September 12th, 2010 @ 04:41 AM

  6. Tanel Suurhans
    Tanel Suurhans

    Could not reproduce this issue on 1.9.2-p0 or 1.8.7 with the same piece of html and javascript (latest jQuery and jQuery UI).
    With both Rails versions the params were properly parsed into an array:

    Parameters: {"post"=>["1", "2", "3", "4", "5", "6", "17", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "18", "19", "20"]}

    September 12th, 2010 @ 11:18 AM

  7. bingbing