简体   繁体   English

最佳就地不是功能Rails 5

[英]Best In Place Is not a function Rails 5

I'm working on a project in Rails 5.1.6 / ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu] My problem is that, following step by step the documentation of the gem best_in_place I get an error. 我正在Rails 5.1.6 / ruby​​ 2.3.1p112(2016-04-26)[x86_64-linux-gnu]中开发一个项目,我的问题是,逐步按照gem best_in_place的文档进行操作时出现错误。 Error: 错误: 在此处输入图片说明

I am a little complicated with the documentation since it is not fully explained how to implement the gem in Rails 5. Any help is useful. 我对文档有点复杂,因为没有完全说明如何在Rails 5中实现gem。任何帮助都是有用的。 Thank you very much! 非常感谢你!

Important data: assets / javascripts / application.js 重要数据:资产/ javascripts / application.js

在此处输入图片说明

assets / javascripts / use_best_in_place.js 资产/ JavaScripts / use_best_in_place.js

在此处输入图片说明

Gemfile 宝石文件

在此处输入图片说明

gem list 宝石清单

views / layout / application.html.erb 视图/布局/ application.html.erb

在此处输入图片说明

Why are you loading jquery twice? 为什么要两次加载jquery? One in application.js and other in views? 一个在application.js中,另一个在视图中?

Try removing the one in views and it should work fine. 尝试删除视图中的一个,它应该可以正常工作。

Just remove this line from your application.html layout (jquery is already require inside application.js from jquery-rails gem): 只需从application.html布局中删除此行(jquery已经在jquery-rails gem的application.js内部要求使用jquery-rails ):

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

It should work this way. 它应该以这种方式工作。

As per the description shared, need to change the below mentioned configuration. 按照共享的说明,需要更改以下提到的配置。

//= require rails-ujs
//= require turbolinks
//= require jquery
//= require best_in_place
//= require best_in_place.jquery-ui
//= require twitter/bootstrap
//= require_tree .

To this one 到这个

//= require rails-ujs
//= require jquery
//= require turbolinks
//= require best_in_place
//= require best_in_place.jquery-ui
//= require twitter/bootstrap
//= require_tree .

Keep turbolinks after jquery always and try to load best_in_place() function after turbolinks loaded. 始终在jquery之后保留best_in_place()并尝试在加载best_in_place()之后加载best_in_place()函数。

# application.js
//= require rails-ujs
//= require jquery
//= require turbolinks
//= require best_in_place
//= require best_in_place.jquery-ui
//= require twitter/bootstrap
//= require_tree .

# assets / javascripts / use_best_in_place.js
$(document).on('turbolinks:load',function(){ 
   jQuery(".best_in_place").best_in_place();
}

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

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