Created
April 14, 2012 16:17
-
-
Save stefl/2385517 to your computer and use it in GitHub Desktop.
Rails button_to helper using a button tag rather than an input tag
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
def button_to_with_button_element(name, options = {}, html_options = {}) | |
fragment = ::Nokogiri::HTML.fragment(button_to(name, options, html_options)) | |
fragment.css("input[type=submit]").each do |input| | |
input.replace ::Nokogiri::HTML.fragment("<button class='#{input.attribute("class")} type='submit'>#{input.attribute("value")}</button>") | |
end | |
raw fragment.to_html | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to add
gem 'nokogiri'
to your Gemfile.