Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rails button_to helper using a button tag rather than an input tag
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>")
raw fragment.to_html

This comment has been minimized.

Copy link
Owner Author

commented Apr 14, 2012

You'll need to add gem 'nokogiri' to your Gemfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.