Re: REST urls and Authenticity Token

AndyV
Mon, 19 May 2008 16:06:05 -0000

It looks like the problem with your first attempt is that you are
using link_to_remote semantics with link_to.  link_to_remote accepts
the ''url'' option, but link_to expects you to provide the url
either
as the first parameter (a string, possibly via a path statement) or
using the url_for parts like :controller and :action.  That''s what
you''ve done in your latest version.  You could format it with named
routes like this:

<%= link_to image_tag(''icons/folder_delete.png''),
        folder_path(folder),
        { :method => :delete,
          :title => ''Delete this folder'',
          :confirm => "All files and subfolders will be deleted!\nAre
you sure?" }
%>

If you want to use the folder name every time time you refer to a
folder you can override the to_param method for your Folder class so
that it returns the folder name.  By default it returns the record
id.  Two caveats:
1. If you use the name rather than the id make sure you validate for
uniqueness.
2. You''ll have to make sure you do some sanitizing for the name (e.g.,
urls cannot use a space and several other characters).

Could #2 be related to your occasional problem with deleting folders?
That is, does it happen consistently when you delete a folder with a
space in the name?

On May 19, 8:15 am, Michael Rigart
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> Michael Rigart wrote:
> > <%= link_to image_tag(''icons/folder_delete.png''),
{:url =>
> > folder_path(folder) }, { :method => :delete, :title =>
''Delete this
> > folder'', :confirm => "All files and subfolders will
be deleted!\nAre you
> > sure?" } %>
>
> Forming the link like this
>
> <%= link_to image_tag(''icons/folder_delete.png''),
{:action => ''destroy'',
> :id => folder }, { :method => :delete, :title => ''Delete
this folder'',
> :confirm => "All files and subfolders will be deleted!\nAre you
sure?" }
> %>
>
> seems to work. But sometims I still get the Authenticity Token error.
> After a page refresh, everything is back in order. Can this be due to my
> redirect?
>
> --
> Posted viahttp://www.ruby-forum.com/.