[LRUG] REST and Delete without JavaScript
Matthew Westcott
matthew.westcott at torchbox.com
Fri Mar 27 04:59:05 PDT 2009
I suppose the best practice way to cater for non-JS users would be to
use button_to, which generates a POST form, and then (assuming you
don't want your JS-enabled users to see a big ugly button) rewrite
that at the JS level into a link with a Javascripty POST mechanism
behind it. I don't know of any off-the-shelf plugin that deals with
this though - surely one must exist. Anyone...?
(:method => :delete is a bit of a red herring incidentally; behind the
scenes Rails rewrites it into a POST action with a tweaked URL,
because browsers can't send DELETE requests natively unless you bring
Ajax into the equation.)
- Matt
On 27 Mar 2009, at 11:41, Simon Sebright wrote:
> Hi,
>
> Perhaps this is already well-known. I am fairly new to Rails and am
> working on an app which uses a RESTful style. I want to offer
> Delete options for the various objects and have first done this with
> the link_to function with :method => :delete.
>
> However, with JavaScript turned off, this is just a link to the
> "showing" of an object.
>
> Now, I know it is not a good idea simply to have a fixed GET link to
> delete something, but want to offer a solution that works both with
> and without JavaScript enabled on the Client Browser. Is there an
> established idiom for this?
>
> I guess the non-JS case needs a form with a POST action, which could
> work just as well with JS via Ajax. Then it seems a shame to have
> bypassed the lovely :method => :delete!
>
> Any pointers?
>
> Thanks,
> Simon
More information about the Chat
mailing list