This project is archived and is in readonly mode.

#4267 ✓invalid
Jelle Vandebeeck

Rails3 (with Ruby 1.9.1) problem when sorting a list

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

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

Comments and changes to this ticket

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) March 27th, 2010 @ 07:57 AM

    • 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?

  • Jelle Vandebeeck

    Jelle Vandebeeck March 27th, 2010 @ 08:45 AM

    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
    
  • Evan Owen

    Evan Owen May 3rd, 2010 @ 06:11 PM

    +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.

  • xds2000

    xds2000 September 12th, 2010 @ 01:36 AM

    • 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

  • Rohit Arondekar

    Rohit Arondekar September 12th, 2010 @ 04:41 AM

    • 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.

  • Tanel Suurhans

    Tanel Suurhans September 12th, 2010 @ 11:18 AM

    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"]}

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages