3

I am using best_in_place gem for my Rails 3.2.1 application. I have no error in my development. When I try to run the application in production, I am getting a script error

$(".best_in_place").best_in_place is not a function in my browser.

In my view page, I have the following code

<%= stylesheet_link_tag "best_inplace", "jquery-ui-1.8.20.custom" %>
<%= javascript_include_tag "application", "jquery.dataTables.min" %>


<%= best_in_place @user, :description, :type => :textarea %>

<script>
  jQuery(".best_in_place").best_in_place();
</script>
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88

2 Answers2

4

Me too had this problem some mins ago, solved by moving the require best_in_place to the end, other places won't work. Weird but works anyway.

This is the application.js manifest

//= require jquery
//= require jquery_ujs
//= require jquery.purr
//= require_tree .
//= require i18n
//= require i18n/translations
//= require best_in_place

$(document).ready(function() {
  $('.best_in_place').best_in_place();
})
JNN
  • 947
  • 10
  • 19
1

The problem is that the function best_in_place()? is declared inside best_in_pace.js, which might still need to be loaded while the code in application.js calling best_in_place() is executed. The proper solution is to enable concatenation of js files through the asset pipeline. This can be done by including

config.assets.debug = false

and/or removing

config.assets.debug = true

in config/environments/development.rb resp. config/environments/production.rb. Then, the place where best_in_pace.js is included does not matter (as long as it comes after jquery.js and before the code calling best_in_place()).

tillmo
  • 607
  • 5
  • 11