I am trying to use Low Pro to add a delete confirmation. In my
controller, I have added a delete and a destroy action. These content
of these actions are:
All of this works when I have javascript disabled. Now I am trying to
add a behavior that will do the confirmation in javascript and if
confirmed then redirect to the destroy action. I am trying to do this
as follows but it is not working.
> I am trying to use Low Pro to add a delete confirmation. In my > controller, I have added a delete and a destroy action. These content > of these actions are:
> All of this works when I have javascript disabled. Now I am trying to > add a behavior that will do the confirmation in javascript and if > confirmed then redirect to the destroy action. I am trying to do this > as follows but it is not working.
> don't change your route, a delete action should not be a GET but a > DELETE.
I think he's using the delete action (note the name) as an intermediary action to hold a form with DELETE method pointing to the _destroy_ action that actually deletes the record. That's pretty much the only way to use an accessible link to perform a destructive action afaik.
> The onclick gets executed but it is not working correctly. Any help > would be appriciated.
So what happens? Does the request get to Rails? Have you used Firebug to debug what happens inside the behaviour (e.g. what does options look like when you make the request)?
Jarkko is correct, I am trying to create both an accessible link (when
Javascript is disabled) and an AJAX request when java is enabled.
After reading your post, I just thought to check my log to see if it
showed anything. It does route but shows an
ActionController::InvalidAuthenticityToken during a call to
request_forgery_protection.
On 24 Jan, 21:40, Jarkko Laine <jar...@jlaine.net> wrote:
> > don't change your route, a delete action should not be a GET but a
> > DELETE.
> I think he's using the delete action (note the name) as an
> intermediary action to hold a form with DELETE method pointing to the
> _destroy_ action that actually deletes the record. That's pretty much
> the only way to use an accessible link to perform a destructive action
> afaik.
> > The onclick gets executed but it is not working correctly. Any help
> > would be appriciated.
> So what happens? Does the request get to Rails? Have you used Firebug
> to debug what happens inside the behaviour (e.g. what does options
> look like when you make the request)?
> Jarkko is correct, I am trying to create both an accessible link (when > Javascript is disabled) and an AJAX request when java is enabled.
> After reading your post, I just thought to check my log to see if it > showed anything. It does route but shows an > ActionController::InvalidAuthenticityToken during a call to > request_forgery_protection.
I have added the following that now works, except for the reload which
does not appear to be working as I intended. For completeness, I have
included my updated delete method.
var AJ =
{
encode_authenticity_token:function( token )
{
return encodeURIComponent( $(token).value )
},
respond_to do |wants|
wants.html do
redirect_to item_path
end
wants.js do
@items = Item.find(:all)
render
end
end
end
On 24 Jan, 23:05, Jarkko Laine <jar...@jlaine.net> wrote:
> On 25.1.2008, at 8.05, KJoyner wrote:
> > Jarkko is correct, I am trying to create both an accessible link (when
> > Javascript is disabled) and an AJAX request when java is enabled.
> > After reading your post, I just thought to check my log to see if it
> > showed anything. It does route but shows an
> > ActionController::InvalidAuthenticityToken during a call to
> > request_forgery_protection.
> This is the new csrf killer in action :-)
> You must pass the authenticity token to the link somehow (seehttp://edgedocs.planetargon.org/classes/ActionController/RequestForge...)
> . You could for example set a header for it in the controller and then
> set the form parameter in your behaviour according to that header.
> I have added the following that now works, except for the reload which > does not appear to be working as I intended. For completeness, I have > included my updated delete method.
> var AJ = > { > encode_authenticity_token:function( token ) > { > return encodeURIComponent( $(token).value )
This is also same as $$('input[name="authenticity_token']).first() (http://prototypejs.org/api/utility/dollar-dollar ). If you give the input field an id, it can be reduced to $ ('authenticity_token').
Notice, that this attaches a behavior to a div with an ID of
item_list. If the element that received the click has a classname of
delete_link, then a confirmation will be displayed and the element
deleted through the destroy method.
On 25 Jan, 00:25, Jarkko Laine <jar...@jlaine.net> wrote:
> On 25.1.2008, at 9.20, KJoyner wrote:
> > I have added the following that now works, except for the reload which
> > does not appear to be working as I intended. For completeness, I have
> > included my updated delete method.
> This is also same as $$('input[name="authenticity_token']).first() (http://prototypejs.org/api/utility/dollar-dollar > ). If you give the input field an id, it can be reduced to $
> ('authenticity_token').