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.

FormHelper's auto_index should create more "friendly" ids or revert back to id_before_type_cast

#2840

sanitized_object_name allows . and : which are perfectly legal according to the specs, but still cause issues with jQuery in particular and I think some browsers as well. It seems to actually complicate things, the to_param is meant for more user friendly urls, I don't see why it would apply to an html tag id where it seems to me the id field would be much more appropriate. I found this ticket http://dev.rubyonrails.org/ticket/9994 but no discussion about it. Is anyone actually using this that wants to_param? If so, why do you prefer that over id?

Reported by Brian Johnson · June 26th, 2009 @ 03:54 AM

State: stale
Milestone: 3.x
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: none

Activity

  1. Brian Johnson
    Brian Johnson

    This ticket is a perfect example of why to_param seems like the wrong thing to do. Imagine an id that is ticket_2840-formhelpers-auto_index-should-create-more-friendly-ids-or-revert-back-to-id_before_type_cast_comment
    Doesn't that seem a little ridiculous?

    June 26th, 2009 @ 03:56 AM

  2. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to wontfix

    It seems like changing this at this point would potentially break people's JavaScript code that rely on the existing behavior for marginal benefit. Can you clarify a bit more what the significant improvement would be that justifies the breakage? Can you provide some examples?

    I'm marking this as wontfix but would be open to revisiting this with some more compelling examples.

    July 2nd, 2009 @ 07:20 PM

  3. Brian Johnson
    Brian Johnson

    what about at least removing . and : from the allowed characters? Technically they're legal, but they do cause issues. I started this ticket because I had a to_param method with a . in it that broke my javascript code and css selectors in Firefox and then I thought it would be better to just use the ID. If your to_param method has a dot in it, css would interpret that as a class selector.

    July 2nd, 2009 @ 07:32 PM

  4. Brian Johnson
    Brian Johnson

    another option would be an option :index => :id_before_type_cast where the symbol would be any method you want to run as the index parameter

    July 2nd, 2009 @ 07:37 PM

  5. Brian Johnson
    Brian Johnson

    if you think that would work, I can come up with a patch, but I don't want to spend time on something that isn't going to be used.

    July 2nd, 2009 @ 07:44 PM

  6. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • Assigned user set to Yehuda Katz (wycats)

    @brian hmmm... I just wanted to point out that at least the jQuery selector engine supports escaping, so you could do $("#myid\.id") or $("#myid\:id") just fine. I'll give this a bit more thought after lunch.

    July 2nd, 2009 @ 08:29 PM

  7. Brian Johnson
    Brian Johnson

    What about this?

    @@@html

    #test.dot {

    color: red;
    

    }

    test



    
    

    July 2nd, 2009 @ 09:58 PM

  8. Brian Johnson
    Brian Johnson

    I'll try that again

    <html>
    <style>
      #test.dot {
        color: red;
      }
    </style>
    <body>
    <div id="test.dot">test</div>
    </body>
    </html>
    

    July 2nd, 2009 @ 10:00 PM

  9. Brian Johnson
    Brian Johnson

    forget it, you can escape there too with .

    July 2nd, 2009 @ 10:05 PM

  10. Brian Johnson
    Brian Johnson

    so I guess maybe there is no real issue with . or : in general, but it doesn't change the fact that it would be nice to have the option to use the id instead. I think the :index => :method_name is a good way to go.

    July 2nd, 2009 @ 10:15 PM

  11. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from wontfix to hold

    @brian If you can make a patch that only adds a net line or two, I'm game!

    July 2nd, 2009 @ 10:17 PM

  12. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from hold to incomplete

    July 2nd, 2009 @ 10:17 PM

  13. Brian Johnson
    Brian Johnson

    ok, I needed two lines to cover nested forms. I used method(method_name).call instead of send because the test was failing on the Structs in the tests, not sure if there is a better way to deal with that.

    July 2nd, 2009 @ 11:30 PM

  14. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  15. Rohit Arondekar
    Rohit Arondekar
    • State changed from incomplete to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:02 AM