Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 :remote => true does not trigger AJAX requests

I have the following:

<%= link_to "Exhibitions", :action => 'tabExhibitions', :id => @app.id, :remote => true %>

It generates:

<div class="tabbarButton" id="tabbarExhibitions">
    <a href="/apps/3/tabExhibitions?remote=true">Exhibitions</a>
</div>

Which results in a common GET request when clicked.

I am new to Rails but my understanding was that setting :remote => true should have created a <a href="..." data-remote=true> instead of a plain link.

I am using jQuery, the necessary headers and meta tags are in place. I should mention this project was upgraded from Rails 2.3.8

Thanks for all the help.

like image 875
Engin Kurutepe Avatar asked Apr 24 '11 22:04

Engin Kurutepe


1 Answers

link_to is putting :remote => true into the url portion of the argument list, and creating a query-string parameter for it (see the parameters in the documentation). Essentially, what you've written is:

<%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id, :remote => true } %>

You'll want to have a separate Hash for the html_options:

<%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id }, :remote => true %>
like image 150
Michelle Tilley Avatar answered Oct 16 '22 09:10

Michelle Tilley