Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Links with data-remote="true" not processing as JSON

I am testing creating a link_to with :remote=> true to get the ajax remote link handling.

<%= link_to "Get Books", "/books", :remote=> true %>

The helper for rails3 resolves the code correctly in the view and I get as source:

<a href="/books" data-remote="true">Get Books</a>

And I have the default javascript included:

<%= javascript_include_tag :defaults %>

And the source head resolves as:

<script src="/javascripts/jquery.js?1302296105" type="text/javascript"></script>
<script src="/javascripts/rails.js?1302139751" type="text/javascript"></script>
<script src="/javascripts/application.js?1305999509" type="text/javascript"></script>

And in the controller I have:

respond_to :html, :json

However when I click the link it loads as regular link, not ajax and on the server log:

Processing by BooksController#index as HTML

What am I missing?

like image 490
Streamline Avatar asked May 27 '11 21:05

Streamline


1 Answers

Make sure that you have installed the jQuery UJS Plugin:

Add this to your gemfile:

gem 'jquery-rails', '>= 1.0.3'

And then run:

bundle install
rails g jquery:install
like image 163
Dylan Markow Avatar answered Sep 23 '22 14:09

Dylan Markow