Created
February 9, 2010 10:49
-
-
Save thechrisoshow/299091 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Delete something | |
# | |
# Takes the following options: | |
# :text The link text (optional) | |
# :message the confirmation message (optional) | |
# :object The object to test for deletable or to use as the path | |
# :path the path for the link | |
# (A path or object must be passed) | |
def delete_link(options={}) | |
object = options[:object] | |
message = options[:message] | |
path = options[:path] | |
text = options[:text] | |
raise "delete_link requires an object OR a path" unless object || path | |
if object.nil? || (object.respond_to?(:deletable?) && object.deletable?) | |
link_to "<span>#{text || 'Delete'}</span>", path || object, | |
:confirm => (message || "Are you sure? This cannot be undone."), | |
:method => :delete, | |
:class => "action delete", | |
:title => "Delete this item" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment