# Changing link\_to (with :method =\> :put) in ajax version

**URL:** <https://www.ruby-forum.com/t/changing-link-to-with-method-put-in-ajax-version/180322>\
**Category:** Rails\
**Created:** [December 17, 2009, 1:19pm UTC](https://www.ruby-forum.com/t/changing-link-to-with-method-put-in-ajax-version/180322 "2009-12-17T13:19:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [December 17, 2009, 1:19pm UTC](https://www.ruby-forum.com/t/changing-link-to-with-method-put-in-ajax-version/180322/1 "2009-12-17T13:19:02Z")

</div>

Im wondering if someone of you have resolved this problem.

If you are using JQuery,  
and you want to replace the onclick event of link generated (with  
link\_to) with a ajax call (PUT)

How should you make it ?

This is the link I would change :

\<%=link\_to ‘I like it’, ilike\_post\_path(post), :class =\> ‘put’, :method  
=\> :put %\>

this is the application.js  
…  
$(‘a.put’)({  
…  
this.unbind(‘click’, false);  
this.click(function() {  
$.put($(this).attr(“href”), …, null, “script”);  
return false;  
})  
…

and this is the problem I have met:  
when I click in the url the browser performs TWO http calls:  
-one with Mime format = text/htmlâ€  
-and one with Mime format = text/javascriptâ€

In practice “this.unbind(‘click’, false)” doesn’t works !  
I could use “this.removeAttr(â€™onclickâ€™)” but I don’t think this is a  
fine way to resolve it.

I hope my explanation was clear 🙂

Have someone else met this problem ?

thank you,  
Alessandro
