Frage

I'm new to rails, and I'm trying to perform an ajax request. Correct me if I'm wrong, but as I understand it, requests are supposed to be performed with a link_to using :remote true.

I have this line of code, which links to the desired page:

    link_to 'Log Out',{:controller=>"ajax_handlers", :action=>"logout"}, :class=>'navButton', :remote=>true

But when I click the link it still navigates to the log out page. I have seen other posts suggesting that this is caused by a syntax error which causes :remote => true to be added to the url as a query parameter. However, the html renders to this:

    <a href="/logout" class="navButton" data-remote="true">Log Out</a>

Which to me looks like it should be working.

A final note: I've seen posts saying that they can't get this working because of some problem with jQuery configuration. However, I am not using jQuery (it could be a javascript configuration error, but I don't know).

Thanks in advance.

War es hilfreich?

Lösung

In Rails 3, :remote => true necessarily requires jQuery and jquery-ujs. You'll need to load them in order to get the functionality you're seeking, even if you don't ever end up using jQuery.

Assuming you're on Rails >3.1, you're using the asset pipeline. By default, the application.js manifest file will load all the files you need. Include the application.js file by adding the following tag to your application.html.erb layout:

# app/views/layouts/application.html.erb
<%= javascript_include_tag :application %>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top