3

Rails 3.2.1 アプリケーションに best_in_place gem を使用しています。私の開発に間違いはありません。本番環境でアプリケーションを実行しようとすると、スクリプト エラーが発生します

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

私のビューページには、次のコードがあります

<%= 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>
4

2 に答える 2

4

私も数分前にこの問題を抱えていましたrequire best_in_placeが、最後まで移動することで解決しました。他の場所は機能しません。奇妙ですが、とにかく動作します。

これはapplication.jsマニフェストです

//= 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();
})
于 2012-06-19T18:45:00.967 に答える
1

問題は、関数best_in_place()?が 内で宣言されていることです。これは、呼び出しbest_in_pace.js中のコードの実行中にロードする必要がある場合があります。適切な解決策は、アセット パイプラインを介して js ファイルの連結を有効にすることです。これは、含めることで実行できますapplication.jsbest_in_place()

config.assets.debug = false

および/または削除

config.assets.debug = true

逆にconfig/environments/development.rbconfig/environments/production.rb. 次に、 が含まれる場所は問題ではありません (コード呼び出しの前後にあるbest_in_pace.js限り)。jquery.jsbest_in_place()

于 2012-12-29T18:47:25.373 に答える