【问题标题】:Can't include x-editable to Rails 6不能将 x-editable 包含到 Rails 6
【发布时间】:2020-01-08 07:35:02
【问题描述】:

我试图在我的项目中包含 x-editable 框架,但它不起作用。

如果我下载框架(来自 http://vitalets.github.io/x-editable/)并将其包含在 packs/ 目录中,我会在控制台中看到 TypeError: $(...).editable is not a function

如果我将<script src="https://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.1/bootstrap3-editable/js/bootstrap-editable.min.js"></script> 包含到/layouts/application.html.slim,错误消息将会改变

TypeError: this.tip(...) is undefined

顺便说一句,在 javascript/packs/application.js 中,我包括了项目所需的框架(我猜):

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require('bootstrap')
require("jquery")
require('packs/announcements')
require('packs/bootstrap-tooltip')
require('packs/bootstrap-popover')
require('packs/bootstrap-editable')
require('packs/bootstrap-editable.min')

bootstrap-tooltip.js 中定义的函数 'tip' 但 cdnjs.cloudflare.com 对此一无所知。我做错了什么以及如何将 x-editable 连接到我的项目?

附: 与 x-editable 相关的其他部分,包括我的项目中的:

宝石文件:

gem 'twitter-bootstrap-rails'
gem 'x-editable-rails'

assets/javascripts/application.js:

//= require jquery
//= require twitter/bootstrap
//= require editable/bootstrap-editable
//= require editable/rails
//= require_tree .

【问题讨论】:

    标签: ruby-on-rails ruby asset-pipeline x-editable ruby-on-rails-6


    【解决方案1】:

    我不确定你是否在使用 Webpacker,但是,如果你是,你可以执行以下操作:

    1) 添加纱线包

    yarn add x-editable
    

    2) 在您的 application.js 中,或者如果您也在使用 Stimulus,您可以将其放入您的控制器文件中

    require('x-editable/dist/bootstrap3-editable/js/bootstrap-editable')
    require('x-editable/dist/bootstrap3-editable/css/bootstrap-editable')
    

    并不是说 x-editable 与 Bootstrap 4 不兼容,但它看起来还不错。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多