Skip to content

Instantly share code, notes, and snippets.

@stefl
Created April 14, 2012 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stefl/2385517 to your computer and use it in GitHub Desktop.
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
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
@stefl
Copy link
Author

stefl 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