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

前端 未结 7 1717
感情败类
感情败类 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:35

    This error occurs when you have not add jquery_ujs file. You just included the jquery file.

    So you need to add both files manually in you view or require them in application.js or any other file which you are using for specific layout.

    Depending upon your scenario, you can follow 1st or 2nd solution.

    1st solution:

    <%= javascript_include_tag :jquery, :jquery_ujs %>
    

    2nd solution:

    1. Require both jquery and jquery_ujs in app/assets/application.js

      //= require jquery.js
      
      //= require jquery_ujs
      
    2. Include application.js file in your specific layout file.

      <%= javascript_include_tag :application %>
      

    Note:

    Also add csrf tag in layout file for both solutions.

    <%= csrf_meta_tag %>
    

    I'm asuming that you have below code in your Gemfile and already installed this Gem.

    gem 'jquery-rails'
    

提交回复
热议问题