简体   繁体   中英

Neither :method => :post and :remote => true is working on my Rails 3.1 app

The HTML that is rendered seems right:

<a href="/foo/add" data-method="post" data-remote="true" rel="nofollow"><img src=/assets/icons/example.png></a>

Inspite of the data-method and data-remote both being rendered, when I click the link, the browser seems to issue a GET because Rails complains about a lack of a route. I do want this to be a POST but I went ahead and added a GET in routes.rb and the call works but is now is a regular call rather than an AJAX call. I seem to be missing some JS file somewhere... very new to Rails 3.1 - can someone point me in the right direction?

Make sure your Gemfile has this:

gem 'jquery-rails'

and that your app/views/layouts/application.html.erb has this:

<%= stylesheet_link_tag :application %>

and that your app/assets/javascripts/application.js contains these 2 lines:

//= require jquery
//= require jquery_ujs

These parts are all needed to properly use the :remote options in Rails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM