0

まず、私の Jquery の知識は非常に限られていますが、これを修正するために読んで練習しているので、これが本当に基本的な質問である場合はご容赦ください。タイトルにあるように、Rails アプリ内でエラー メッセージが表示されます

  $(".share a").button is not a function

私のapplication.jsファイルにはこれが含まれています

  $(function() {

  $(".share a")
  .button()
  .click(function() {

    var a = this;

    // first set the title of the dialog box to display the folder name
    $("#invitation_form").attr("title", "Share '" + $(a).attr("folder_name") + "' with others");

    // a hack to display the different folder names correctly
    $("#ui-dialog-title-invitation_form").text("Share '" + $(a).attr("folder_name") + "' with others");

    // then put the folder_id of the share link into the hidden field "folder_id" of the invite form
    $("#folder_id").val($(a).attr("folder_id"));

    // the dialog box customization
    $("#invitation_form").dialog({
      height: 300,
      width: 600,
      modal: true,
      buttons: {
        // first button
        "Share": function() {
          // get the url to post the data to
          var post_url = $("#invitation_form form").attr("action");

          // serialize the form data and post it the url with ajax
          $.post(post_url, $("#invitation_form form").serialize(), null, "script");

          return false;
        },
        // second button
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      close: function() {
      }
    });

    return false;
  });

});

そして、私のビューページにはjqueryを呼び出すためにこれが含まれていました(私は思う)

  <div class="share">
        <%= link_to "Share", "#", :folder_id => folder.id, :folder_name =>       folder.nameunless @is_this_folder_being_shared %>
      </div>

なぜこのエラーが発生するのか、誰でもアドバイスできますか? 共有というラベルの付いたボタンをクリックすると、招待フォームとともにポップアップ ウィンドウが表示されます。

この時点で立ち往生しているので、助けていただければ幸いです-最後に、Jquery UIを含めるのを忘れた可能性があるとアドバイスされましたが、アプリにこのライブラリがありますが、2つの競合するライブラリがあるかどうか疑問に思い始めましたjquery-ui と jquery-ui-1.8.9.custom.min.js が同じディレクトリにありますか? これが事実であるかどうかを誰かが知っていますか?

これは私のアセット パイプラインです

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

および jquery-ui-1.8.9.custom 私のjavascripts(そこには他のUIはありません)

4

1 に答える 1

1

は読み込まれてjquery-ui.jsいますが、ブラウザのjavascriptエンジンが関数を見つけることができないため、button使用しているjquery-uiビルドから「ボタン」ウィジェットが除外されていることが原因である可能性があります。これを確認するには、ウィジェットを含む新しいスクリプトを作成し、現在のの代わりにそれを使用しjquery-ui.jsます。それがうまくいくなら、それがあなたの答えです。

于 2012-04-23T20:03:49.243 に答える