This project is archived and is in readonly mode.

#3029 ✓wontfix
Kieran P

[PATCH] Non JavaScript dependent record deletion solution

Reported by Kieran P | August 10th, 2009 @ 03:01 AM

At the moment, to delete a record you need Javascript enabled. I've created a patch which adds a new delete action to controllers. Any link_to with :method => :delete now point to the delete path. The javascript still works though if they have it enabled.

Attached is a patch with the changes to make this happen, along with documentation, and tests. I'm new to the Rails source code, so if I've change more or less than I was supposed to, please forgive me.

Comments and changes to this ticket

  • Rizwan Reza

    Rizwan Reza August 10th, 2009 @ 04:28 AM

    I remember Yehuda had said something about this in his presentation at Railsconf. Rails is going to handle this through HTML5, I guess.

  • Kieran P

    Kieran P August 10th, 2009 @ 05:20 AM

    Even with HTML5, I don't see a way of providing Javascript independent record deletion without either adding a delete method (as the patch does) or hacking the destroy method (which seems ugly to me).

    At least with the delete method, you can add logic to check if it can be deleted before hitting the destroy action (as is needed in a project I'm working on).

  • Jeremy Kemper

    Jeremy Kemper August 10th, 2009 @ 05:24 AM

    • State changed from “new” to “wontfix”

    Nice patch. I'm not a fan of adding a million delete confirmation pages, esp. in core. This would make a great plugin, however!

  • Jeremy Kemper

    Jeremy Kemper August 10th, 2009 @ 05:24 AM

    • Tag changed from bugmash, delete, destroy, javascript, rails, scafold to delete, destroy, javascript, rails, scafold
  • Elad Meidar

    Elad Meidar August 10th, 2009 @ 05:25 AM

    • Tag changed from delete, destroy, javascript, rails, scafold to bugmash, delete, destroy, javascript, rails, scafold

    -1 i think it's better to leave it out, assuming that you add a delete method is somewhat not so RESTful imo. if there is a planned solution for a later version of rails based on HTML5 (whenever that's gonna be widely supported) i think it's better to keep it as it is atm.

  • Jeremy Kemper

    Jeremy Kemper August 10th, 2009 @ 07:10 AM

    • Tag changed from bugmash, delete, destroy, javascript, rails, scafold to delete, destroy, javascript, rails, scafold
  • Kieran P

    Kieran P August 10th, 2009 @ 07:13 AM

    • Tag changed from delete, destroy, javascript, rails, scafold to bugmash, delete, destroy, javascript, rails, scafold

    Jeremy, its not a million confirmation pages. If Javascript is enabled, it continue to do the prompt/destroy functionality. It'll only render the delete action if they have JavaScript off when they click the Delete link.

    Elad, whats not restful about it?

    new -> create
    edit -> update
    delete -> destroy

    I'd be interested to hear how HTML5 will fix the issue... I suspect it'll just make the HTML easier to plugin into with Javascript and not actually fix the problem.

  • Jeremy Kemper

    Jeremy Kemper August 10th, 2009 @ 07:25 AM

    • Tag changed from bugmash, delete, destroy, javascript, rails, scafold to delete, destroy, javascript, rails, scafold

    It's a delete route, action, and view on every controller and it begs for confusion with destroy.

    (HTML5 has no bearing here.)

  • Erik Ostrom

    Erik Ostrom August 10th, 2009 @ 07:52 AM

    FYI, Rails Magazine #2 (http://railsmagazine.com/issues/2) explains the HTML 5 thing. It doesn't eliminate the JavaScript dependency.

    I'm +1 on eliminating the JavaScript dependency for delete, but I'm -1 pessimistic about the non-JavaScript scaffolding being maintained effectively.

    http://www.napcsweb.com/blog/2009/07/01/accessible-rails-apps-rails... suggests another option: use button_to to generate a form consisting of hidden fields and a destroy button, and then use unobtrusive JavaScript to turn the form into a link for JS-enabled users.

    I can imagine hacking link_to(..., :method => :delete) to do this automatically, but I'm not offering to do it.

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>

People watching this ticket

Attachments

Pages