Rails form_for :remote=>true is not calling js method

前端 未结 7 1741
感情败类
感情败类 2020-12-01 09:11

I have no idea why this is not working, I\'m learning rails and I\'m following a book it says to do it like this:

    <%= form_for([@article,@article.comm         


        
7条回答
  •  隐瞒了意图╮
    2020-12-01 09:58

    Most likely what happens is that you are missing the rails.js file, which handles that for you, whether you are using prototype or jquery.

    If you are using jQuery, the easiest way to get all the needed files is using the jquery-rails gem. This will add a generator to install jquery and the needed rails.js.

    type something like inside your rails application root:

    rails g jquery:install
    

    And then, inside your application.html.erb add the line

    <%= javascript_include_tag :defaults %>
    

    or explicitly (do not forget to include your jquery separately):

    <%= javascript_include_tag :rails, :application %>
    

    [EDIT: for Rails 3.1 or greater using the asset pipeline]

    Use the jquery-rails gem (as mentioned above) and add the following lines to the app/assets/javascripts/application.js (if they are not there already) :

    //= require jquery
    //= require jquery_ujs
    

    Hope this helps!

提交回复
热议问题