我想自定义确认对话框。在我自定义确认对话框之前,一切都很完美。当我点击删除链接
<%= link_to image_tag("icon_delete.png", :border => 0), user, method: :delete ,data: { confirm: 'Are you sure delete:' + user.email } %>
浏览器显示默认的确认弹出窗口,我在 UserController 中按下 OK->this link call destroy()。现在,我在 user.js.coffee 中实现自定义确认弹出窗口
$.rails.allowAction = (link) ->
return true unless link.attr('data-confirm')
$.rails.showConfirmDialog(link) # look bellow for implementations
false # always stops the action since code runs asynchronously
$.rails.confirmed = (link) ->
link.removeAttr('data-confirm')
link.trigger('click.rails')
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
html = """
<div class="modal" id="confirmationDialog">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Are you sure Mr. President?</h3>
</div>
<div class="modal-body">
<p>#{message}</p>
</div>
<div class="modal-footer">
<a data-dismiss="modal" class="btn">Cancel</a>
<a data-dismiss="modal" class="btn btn-primary confirm">OK</a>
</div>
</div>
"""
$(html).modal()
$('#confirmationDialog .confirm').on 'click', -> $.rails.confirmed(link)
这一次,当我点击删除链接时 -
- 浏览器未显示自定义确认弹出对话框或默认弹出对话框
- 在 UserController 中调用的链接
show()
而不是destroy()
--> 这里发生了什么,在我实现自定义确认对话框之前一切正常。我没有更改 route.rb 中的任何内容。
我使用 Ruby 1.9.3 版和 Rails 4.0.0 版。我的资产/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
宝石文件
gem 'sass-rails', '~> 4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
有人可以帮我吗?