This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a link to an action. A confirm box will pop up before | |
# you can process to action specified here. | |
# link_to_action "Delete", "Are you sure?", :method => 'delete', | |
# :class => "negative", :controller => 'price_letters', | |
# :action => 'destroy', :id => letter.id | |
# link_to_action "Effect Now", "Take effect now, and can not be reversed?", | |
# :controller => "price_letters", :action => 'effect_now', :id => letter.id | |
def link_to_action(link_text, msg = "Are you sure", attributes = {}) | |
content = (msg || "Are you sure?") | |
attrs = { :method => 'post' } | |
attrs = attrs.merge(attributes) | |
%{<a href="/#{attrs[:controller]}/#{attrs[:action]}/#{attrs[:id]}" | |
onclick="if (confirm('#{content}')) | |
{ | |
var f = document.createElement('form'); | |
f.style.display = 'none'; | |
this.parentNode.appendChild(f); | |
f.method = 'POST'; | |
f.action = this.href; | |
var m = document.createElement('input'); | |
m.setAttribute('type', 'hidden'); | |
m.setAttribute('name', '_method'); | |
m.setAttribute('value', '#{attrs[:method]}'); | |
f.appendChild(m);f.submit(); | |
} | |
return false;" class="#{attrs[:class]}">#{link_text}</a>} | |
end |
No comments:
Post a Comment