Richlewis
Richlewis

Reputation: 15384

Jquery assistance needed ( Rails 3)

Firstly my Jquery knowledge is very limited but am reading and practicing to remedy this, so please bear with me if this is a really basic question. As the title states i am getting a error message within my rails app

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

My application.js file contains this

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

});

And my view page containds this to call the jquery ( I think)

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

Can anyone advise why I am getting this error as from what i can see it should be working, I.E. when i click a button labelled share I should get a popup window appear with my invitation form.

Any help appreciated as I am now stuck at this point- Finally I was advised that I may have forgotten to include Jquery UI, but i have this library in my app, though I have started to wonder if I have 2 conflicting libraries as I have Jquery-ui and jquery-ui-1.8.9.custom.min.js in the same directory? Does anyone know if this is could be the case?

This is my asset pipeline

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

and jquery-ui-1.8.9.custom in my javascripts ( No other UI in there)

Upvotes: 0

Views: 101

Answers (1)

PinnyM
PinnyM

Reputation: 35531

Since jquery-ui.js is loading, but the browser javascript engine can't find the function button, it is likely that the problem is due to the 'button' widget being left out of the jquery-ui build that you are using. You can verify this by building a new script that includes the widget, and using that in place of the current jquery-ui.js. If it works then that's your answer.

Upvotes: 1

Related Questions