Method: Merb::Helpers::Form#delete_button

Defined in:
lib/merb-helpers/form/helpers.rb

#delete_button(object_or_url, contents = "Delete", attrs = {}) ⇒ Object

Generates a HTML delete button.

If an object is passed as first parameter, Merb will try to use the resource url for the object If the object doesn’t have a resource view, pass a url

Parameters

object_or_url<Object> or <String>

Object to delete or URL to send the request to

contents<String>

HTML contained within the button tag

attrs<Hash>

HTML attributes

Returns

String

HTML

Example

<%= delete_button @article, "Delete article now", :class => 'delete-btn' %>
<%= delete_button url(:article, @article)%>


394
395
396
397
398
399
400
401
# File 'lib/merb-helpers/form/helpers.rb', line 394

def delete_button(object_or_url, contents="Delete", attrs = {})
  url = object_or_url.is_a?(String) ? object_or_url : resource(object_or_url)
  button_text = (contents || 'Delete')
  tag :form, :class => 'delete-btn', :action => url, :method => :post do
    tag(:input, :type => :hidden, :name => "_method", :value => "DELETE") <<
    tag(:input, attrs.merge(:value => button_text, :type => :submit))
  end
end