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.

link_to does not respect options like :confirm and :popup if url is specified as part of :options itself

#3841

The problem occurs when link_to is used as follows

<%=link_to "Delete asset",:action=>"delete",:controller=>"post",:id=>post.id,:confirm=>"Do u want 
to delete this post"%>
The generated link looks like this
<a href="/post/delete/14?confirm=Do+u+want+to+delete+this+post">
However using
<%=link_to "Delete asset","post/delete/#{post.id}",:confirm=>"Do u want to delete this post"%>
gives the proper result

Reported by Rajalakshmi Ramesh · February 3rd, 2010 @ 01:46 PM

State: invalid
Milestone: none
Assigned to: Ryan Bigg Ryan Bigg
Importance: Low

Activity

  1. Samuel Danielson
    Samuel Danielson

    The proper results in

    <%=link_to "Delete asset","post/delete/#{post.id}",:confirm=>"Do u want to delete this post"%>
    

    are due to you passing :confirm as the third argument, which is "html_options". Break :confirm into the third arg so it gets passed as html_options.

    <%=link_to "Delete asset",{:action=>"delete",:controller=>"post",:id=>post.id},{:confirm=>"Do u want 
    to delete this post"}%>
    

    On a related note this has changed in edge. Some keys in html_options are converted to data-#{key}. Others, like :href, override the default. This is for the new javascript and rest stuff.

    <%= link_to 'hello from edge', '', :batman_sidekick => 'robin', :confirm => 'Sure?' %>
    
    <a href="" batman_sidekick="robin" data-confirm="Sure?">hello from edge</a>
    

    February 4th, 2010 @ 04:21 PM

  2. Rishav Rastogi
    Rishav Rastogi
    • Assigned user set to Ryan Bigg

    Invalid. Not using link_to properly as mentioned in the above comment.

    April 11th, 2010 @ 12:01 AM

  3. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    I will mention also here that it's probably best to use the RESTful helpers for this (assuming you set them up in config/routes.rb first!

    <%= link_to 'delete asset', post_path(post), :method => :delete, :confirm => "Do you want to delete this post?" %>
    

    April 11th, 2010 @ 12:08 AM