Forum: Ruby on Rails Rails + jQuery and Links

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6f3a904bebab756df4880aeb199da396?d=identicon&s=25 sshefer (Guest)
on 2008-12-16 10:26
(Received via mailing list)
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.
This topic is locked and can not be replied to.