简体   繁体   English

Ruby on Rails best_in_place宝石抛出错误

[英]Ruby on Rails best_in_place gem throwing error

I am following the guide on https://github.com/bernat/best_in_place When I run my app I get the error below: What does this mean??? 我正在遵循https://github.com/bernat/best_in_place上的指南,当我运行我的应用程序时,出现以下错误:这是什么意思???

%table
  - @schedules.each do |s|
    %tr
      %td= best_in_place s, :name

$(document).ready(function() {
  /* Activating Best In Place */
  jQuery(".best_in_place").best_in_place();
});

Uncaught TypeError: Object [object Object] has no method 'best_in_place'

First, you need to ensure that the best_in_place gem is installed to your environment and the JavaScript file is being imported to your HTML. 首先,您需要确保将best_in_place gem安装到您的环境中,并将JavaScript文件导入到HTML中。 If you're using the asset pipeline (Rails 3.1+), you can include it in your JavaScript manifest: 如果您正在使用资产管道(Rails 3.1+),则可以将其包括在JavaScript清单中:

# app/assets/javascripts/application.js
//= require jquery
//= require jquery-ui
//= require best_in_place

Then, ensure that the script has an HTML DOM element(s) that it can bind to and execute the best_in_class function upon: 然后,确保脚本具有可绑定到的HTML DOM元素,并在best_in_class执行best_in_class函数:

# in your view
<div class="best_in_class"></div>

You need to include best_in_place lib before using it 您需要先包含best_in_place库,然后再使用它

//= require best_in_place

to your appplication.js file 到您的appplication.js文件

Remove app/assets/javascripts/best_in_place.js 删除app / assets / javascripts / best_in_place.js

Include activating code in view: 在视图中包括激活代码:

%table
  - @schedules.each do |s|
    %tr
      %td= best_in_place s, :name
:javascript
$(document).ready(function() {
  /* Activating Best In Place */
  jQuery(".best_in_place").best_in_place();
});

I was having the same error. 我有同样的错误。 I restarted the server and it worked for me. 我重新启动服务器,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM