Rails-自定义确认对话框

时间:2013-10-09 15:06:16

标签: ruby-on-rails confirmation customdialog

<%= link_to image_tag("icon_delete.png", :border => 0), user, method: :delete ,data: { confirm: 'Are you sure delete ' + user.email } %>

当用户点击此链接时,我想要一个自定义确认对话框,而不是简单地显示confirm('Are you are')

我读过许多帖子,例如http://lesseverything.com/blog/archives/2012/07/18/customizing-confirmation-dialog-in-rails/。但是,我遇到问题Sprockets::EncodingError

有更好的解决方案吗?

更新

在实施自定义确认对话框之前一切正常,编码成功后,这次

<%= link_to image_tag("icon_delete.png", :border => 0), user, method: :delete ,data: { confirm: 'Are you sure delete ' + user.email } %>

实际上,当我点击删除图标时,没有弹出显示,这个链接没有调用UserController中的destroy()。在UserController上调用了show()。这里发生了什么?

$.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) 

文件route.rb      root:to =&gt; “用户#指数”

 devise_for :users, :controllers => {:registrations => "users"}
 resources :users
 match '/admin',   to: 'users#admin',   via: 'get'

1 个答案:

答案 0 :(得分:0)

听起来像是你正在看的同一个问题。听起来解决方案是使用文本编辑器打开.js文件并将其保存为UTF-8编码。

转到“使用编码保存”菜单,然后选择“UTF-8”。

在Sublime Text 2中,这是在文件&gt;使用编码保存&gt; UTF-8。