Rails: link_to with: remote => true not working

I am trying to implement a voting system like here in Stack Overflow. (Using Rails 3) I want the vote to be done without reloading the page, so I have this code

link_to("/tags/#{tag.id}/upVote", :remote => true )

And so, in my / views / tags directory, I have a file called _upVote.js.erb, which I thought would be called when this link is clicked, but it doesn’t. It tries to treat upVote as HTML, and this is the error I get

Missing / upVote template tag with {: formats => [: html]

Also, here is what I have in the routes file

match "tags/:id/upVote" => "tags#upVote"

Any ideas how I can make this work?

+3
source share
4 answers

, , , Ajax. jQuery jQuery Rails: http://github.com/rails/jquery-ujs

Firefox + Firebug, , Ajax.

+6

. ,

, ,

Require both jquery and jquery_ujs were in the application.js manifest.
//= require jquery
//= require jquery_ujs

Rails ajax .

+2
+1

- rails:

rails g jquery:install

application.html.erb

<%= javascript_include_tag :defaults %>

( jquery ):

<%= javascript_include_tag :rails, :application %>

[EDIT: Rails 3.1 ]

gem jquery-rails ( ) app/assets/javascripts/application.js ( ):

//= require jquery
//= require jquery_ujs

, !

0

Source: https://habr.com/ru/post/1772049/


All Articles