Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Ajax call with rails link_to

I cannot disable JQuery mobile Ajax call for a link_to.

I have a link with a redirect

 <%= link_to 'test',  my_post_path, :method => :post, "data-role" => "button", "rel" => "external", "data-ajax"=>"false", "data-inline" => "true", "data-icon" => "plus",  "data-iconpos" => "left" %>

This is traslated in the following html

<a href="/my_post" data-ajax="false" data-icon="plus" data-iconpos="left" data-inline="true" data-method="post" data-role="button" rel="external nofollow">test</a>

my_post is just a redirect to

   def my_post
      redirect_to another_method_path(....)
    end

I tought that setting data-ajax=false would have been sufficient to disable Ajax for this link, but it is not. another_method_path is called first, leaving me with my_post_path.

If I disable Ajax totally

 $.mobile.ajaxEnabled = false;

It is working as expected.

Am I doing something wrong in the localise link_to?


1 Answers

i think that setting rel: :external on the link should do the trick already.

see the section "Linking without Ajax" here: http://jquerymobile.com/demos/1.1.1/docs/pages/page-links.html

i guess that the problem is :method => :post in your link, as this will only work with forms or ajax.

like image 78
phoet Avatar answered Jan 20 '26 11:01

phoet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!