# Rails + jQuery and Links

**URL:** <https://www.ruby-forum.com/t/rails-jquery-and-links/155747>\
**Category:** Rails\
**Created:** [December 16, 2008, 10:26am UTC](https://www.ruby-forum.com/t/rails-jquery-and-links/155747 "2008-12-16T10:26:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [December 16, 2008, 10:26am UTC](https://www.ruby-forum.com/t/rails-jquery-and-links/155747/1 "2008-12-16T10:26:34Z")

</div>

Hi,

I currently have a “save for later” function that effectively allows a  
logged in user to save an position for later viewing. (Similar to the  
watch/unwatch function on github). In my scenario I have a Position  
model. Saved positions are resources that belong to the Position,  
using the current\_user before creation or deletion to create that user  
association.

To do this I am doing a POST directly using the link:

\<%= link\_to(‘Save for Later’,  
position\_saved\_position\_url(@position),  
:method =\> :post, :class =\> “new\_saved\_position”)-%\>

However, in my application.js my code seems to still submit the link  
and ignore the “return false;” at the end.

$(’.new\_saved\_position’).click(function(){  
$.ajax({  
type: “POST”,  
url: $(this).href,  
dataType: “script”,  
beforeSend: function(xhr) {xhr.setRequestHeader(“Accept”, “text/  
javascript”);}  
});  
return false;  
});

My question:

By adding “:method =\> :post” am I altering/tainting the way this  
should be done? I realize that having a direct POST like this is not  
Restful - are there better ways of doing this? While not the topic of  
this board - is my jQuery code wrong?

Thanks.
