0
<%= 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">×&lt;/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 根 :to => "users#index"

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

1 回答 1

0

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

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

在 Sublime Text 2 中,这是在 File > Save with Encoding > UTF-8 中。

于 2013-10-09T16:13:24.897 回答