简体   繁体   中英

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. 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. Thank you very much!

Important data: assets / javascripts / application.js

在此处输入图片说明

assets / javascripts / use_best_in_place.js

在此处输入图片说明

Gemfile

在此处输入图片说明

gem list

views / layout / application.html.erb

在此处输入图片说明

Why are you loading jquery twice? One in application.js and other in views?

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):

<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.

# 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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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