#365 new
Edwin Vlieg

Allow Webrat to read the data-method attribute

Reported by Edwin Vlieg | March 12th, 2010 @ 08:36 AM

Rails 3 will contain unobtrusive JavaScript helpers, allowing easy switching between JavaScript frameworks. By making use of the new data attributes of HTML5, Rails stores information about the action to take. In case of a link with a delete HTTP method, Webrat won't work:

link_to "Delete", instance, :method => :delete

In Rails 3, this will produce the following HTML:

<a href="/instance/123" data-method="delete">Delete</a>

The following monkey patch makes use of the "data-method" attribute and allows Webrat to follow delete links in Rails 3.

module Webrat
  class Link < Element
    def http_method
      if !@element["data-method"].blank?
        @element["data-method"]
      elsif !onclick.blank? && onclick.include?("f.submit()")
        http_method_from_js_form
      else
        :get
      end
    end
  end
end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Pages