javascriptjqueryruby-on-railsbest-in-place

best_in_place is not a function


I can't get it to work. I've followed the installation process described here. Other solutions on this site have not helped. I keep getting this error on Developers tools

static_pages.self-8c8a5c3….js?body=1:7 Uncaught TypeError: JQuery(...).best_in_place is not a function

On the controller's coffee file:

$(document).on 'ready page:load', ->
  jQuery(".best_in_place").best_in_place();
  return

I've also tried calling it on the view itself

<script type = 'text/javascript'>
 $(document).ready(function() {
   /* Activating Best In Place */
   jQuery(".best_in_place").best_in_place();
});
</script>

application.js

//= require jquery
//= require best_in_place
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui
//= require best_in_place.jquery-ui
//= require bootstrap
//= require turbolinks 
//= require_tree . 

I've even tried without best_in_place.jquery-ui and changing the order below require_tree of both best_in_place

This is my Gemfile:

gem 'rails', '4.2.6'
gem 'sqlite3'
gem 'devise', '~> 3.5', '>= 3.5.6'
gem 'best_in_place', '~> 3.0.1'

gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jquery-ui-rails', '~> 5.0', '>= 5.0.5'
gem 'simple_form'
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'haml-rails', '~> 0.9.0'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'sass-rails', '~> 5.0' 
gem 'will_paginate', '~> 3.1'
gem 'bootstrap-editable-rails', '~> 0.0.9'

I've tried with gem 'best_in_place', github: 'bernat/best_in_place' as some sites suggested.


Solution

  • I was redefining the Jquery Library. As expressed in the documentation, Best-in-place should be placed after Jquery on application.js

    //= require jquery
    //= require jquery.turbolinks
    //= require jquery_ujs
    //= require jquery-ui
    //= require best_in_place
    //= require best_in_place.jquery-ui
    

    But my applications.html.erb had the following :

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
    

    overwriting my previous declaration.