我正在将所有.js
和.css
文件添加到预编译中,如下所示
Rails.application.config.assets.precompile = ['*.js', 'application.scss', '*.scss', '*.css.erb']
并在application.js
部分中加入head
,如下所示
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
即使某些, js
文件在我的观看中不可用。我在该目录中有一个名为image-picker.js
的文件。这使.imagepicker()
功能在我的观看中可用,但是它会抛出这样的错误
Uncaught TypeError: $(...).imagepicker is not a function
但是当我特意使用
包含该页面的.js
文件时
<%= javascript_include_tag "image-picker" %>
更新
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require image-picker.js #tried but not working.
//= require_tree .
UPDATE2
正在使用jquery-rails - 4.3.1
和jquery-ui-rails 6.0.1
将jquery-2.1.4.min.js
添加到我的资产中。但是当我使用//= require jquery
时,我认为它不包括应用程序的jquery。
当我尝试手动添加它时,一切正常,
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-2.1.4.min #now everything working fine. it seems a dependency problem.
//= require image-picker.js #tried but not working.
//= require_tree .
我想知道这是什么原因。感谢。
您可以找到非常相似的问题 - here
答案 0 :(得分:0)
尝试在image-picker.js
application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require image-picker
//= require_tree .