Uncaught ReferenceError: $ is not defined rails

前端 未结 7 2094
后悔当初
后悔当初 2021-01-11 11:08

I\'m trying to add Froala editor to my project.

Problem only on production server(on localhost it works fine) I\'m using rails 4.1.0 In gemfile i\'m have

<         


        
相关标签:
7条回答
  • 2021-01-11 11:14

    An solution working for me is:

    Separate files

    create assets/javascripts/jquery_init.js content :

    //= require jquery
    //= require jquery.turbolinks
    //= require jquery.cookie
    //= require jquery.ui.all
    //= require jquery_ujs
    

    an call before aplication.js

    <%= javascript_include_tag "jquery_init" %>
    <%= javascript_include_tag "application", :async => !Rails.env.development?, "turbolinks-data-track" => true %>
    
    0 讨论(0)
  • 2021-01-11 11:15

    Replace application.html.erb

    <%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
    

    to

    <%= javascript_include_tag "application" %>
    
    0 讨论(0)
  • 2021-01-11 11:15

    try switching these lines:

    <%= javascript_include_tag "vendor/modernizr" %>
    <%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
    

    will become

    <%= javascript_include_tag "application" 'data-turbolinks-track' => true %>
    <%= javascript_include_tag "vendor/modernizr" %>
    
    0 讨论(0)
  • 2021-01-11 11:15

    Here's what I did, it worked for me:

    Surround your script with window.onload = function () { }; so your js will be executed only when the page load:

    window.onload = function () {
      $(function() {
        $('div#content').editable({
          inlineMode: false
        })
      });
    };
    
    0 讨论(0)
  • 2021-01-11 11:26

    This was my solution:

    Put this in your app/assets/javascripts/application.js

    //= require jquery
    //= require jquery_ujs
    

    and install this gem file:

    gem 'jquery-rails'
    
    0 讨论(0)
  • 2021-01-11 11:27

    How do you have the foundation added to the project?

    In app/assets/javascripts/aplication.js

    I had the same error

    $ is no defined

    and I resolved by reloading the foundation js this way:

    jQuery(document).ready(function($) {
    $(document).foundation();
    });
    
    0 讨论(0)
提交回复
热议问题