简体   繁体   中英

Rails-customize confirm dialog

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

When user clicks on this link, I want a custom confirm dialog instead of simply showing confirm('Are you are') .

I've read many threads, for example http://lesseverything.com/blog/archives/2012/07/18/customizing-confirmation-dialog-in-rails/ . However, I hit on issue Sprockets::EncodingError .

Any better solution?

UPDATE

Everything ok before implemented customized confirmation dialog,After encoding successful, This time

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

Actually,When I click on delete icon,no popup show and this link didn't call destroy() in UserController.It called show() on UserController.What's going on here?

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

File route.rb root :to => "users#index"

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

Sounds like it's the same issue you're looking at. It sounds like the solution is to open the .js file with a text editor and save it as UTF-8 encoding.

Go to "Save with Encoding" menu and choose "UTF-8".

In the Sublime Text 2 this is in File > Save with Encoding > UTF-8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM