Ruby on Rails best_in_place gem throwing error

核能气质少年 提交于 2019-12-11 19:29:31

问题


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

%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'


回答1:


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. If you're using the asset pipeline (Rails 3.1+), you can include it in your JavaScript manifest:

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

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



回答2:


You need to include best_in_place lib before using it

//= require best_in_place

to your appplication.js file




回答3:


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



回答4:


I was having the same error. I restarted the server and it worked for me.



来源:https://stackoverflow.com/questions/18541000/ruby-on-rails-best-in-place-gem-throwing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!