Cannot open multiple jquery ui dialog box in rails 3
please help with this using rails 3 and jquery-ui.
In my view i have:<div class="container">
<div class="contents">
<% @questions.each do |question| %><br />
<li>
<button class="opendialog">Delete</button>
<div class="info" title="Delete Request">
Question:<b><%= question.content %></b>
</div>
</li>
<% end %>
</div>
</div>
and in my application.js i have:
$(function() {
$('.opendialog').each(function() {
$.data(this, 'dialog',
$(this).next('.info').dialog({
autoOpen: false,
modal: true
})
);
}).click(function() {
$.data(this, 'dialog').dialog('open');
return false;
});
});
The problem that i am having is that none of the dialogs open, when i click their respective buttons. The code works fine in jsfiddle here, but no luck in my code.How can i solve this.In my app there are places that i open single dialog boxes and works fine, its just this code that does not want to open the dialogs when i click the respective buttons.
Thank开发者_如何学JAVAs for the help.
After some googling, i found that i was loading in my stylesheets incorrectly.
I was including the .js files like this
1). Create new project skip prototype with -J:
rails new -J test -d mysql
2). Modify the Gemfile, add JQuery:
gem 'jquery-rails'
3). Bundle update:
bundle update rails
4). Generator the JQuery, --ui means withe JQuery UI:
rails generate jquery:install --ui
5). Modify the config/application.rb:
config.action_view.javascript_expansions[:defaults] = %w(jquery jquery-ui rails application)
Notice how in the application.rb file I was loading application.js.
Then in my application.html.erb file i was loading in application.js like this
<%= javascript_include_tag :defaults %>
However when I viewed the source of my html I noticed that the application.js was being loaded twice causing a conflict.
In application.rb I then changed the line to:
config.action_view.javascript_expansions[:defaults] = %w(jquery jquery-ui rails)
restart server and all is good. Simple error
精彩评论