views:

100

answers:

2

In Haml, I've been trying to get the following link_to_remote call to work. It's called from the /questions/new view.

#{link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart'}}

I've tried the following variations.

#{link_to_remote image_tag('x.png'), :url => {:controller => :questions, :action => :remove_tag_from_cart}}
#{link_to_remote image_tag('x.png'), :controller => 'questions', :action => 'remove_tag_from_cart'}
#{link_to_remote image_tag('x.png'), :controller => :questions, :action => :remove_tag_from_cart}

In every case, I get the following link: /questions/new#. I'm not sure why!

I also have the following in routes.rb, thinking that was the problem...

map.connect ':controller/remove_tag_from_cart', :action => 'remove_tag_from_cart'
A: 
map.connect ':controller/remove_tag_from_cart', :controller=>:controller , :action => 'remove_tag_from_cart'

Restart server and check.

EDITED

link_to_remote use for the ajax request. so when you hover the link you will get your url append with # but when you click on it it call the ajax request to a url provided by you. i explain it below.

<%= link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart'}} %>

when you check generated html using it you will get

<a onclick="new Ajax.Request('/questions/remove_tag_from_cart', {asynchronous:true, evalScripts:true}); return false;" href="#">
   <img src="/images/x.png" alt="X"/>
 </a> 

you can see href="#" in your generated html

Note:if you don't want it either you have to use link_to.

Salil
Thanks, but that doesn't solve the problem... >_>
Teef L
check my edited answer.
Salil
Awesome. Thanks!
Teef L
A: 

if /questions/new# is what shown in your status bar in browser then check page source again because link_to_remote generates javascript ajax request and actual link is hidden inside onclick attribute

keymone