Forum: Ruby on Rails Overriding html generated for submit_tag and selected links

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0745ba84f0eae09dd0ba69b14ddf4a2a?d=identicon&s=25 steve (Guest)
on 2009-04-19 15:11
(Received via mailing list)

Probably something simple, but I'm trying to change my submit_tag and
other buttons to CSS based buttons based on the article at

Basically this needs the following HTML markup:

<a class="button" href="#"><span>Button Text</span></a>

So, the question is how can I change the generated HTML (or better yet
create a helper) to allow me to spit this out for form actions and
some link_to's, specifically the inner <span> bit?

Any help would be appreciated as my google-fu has not been strong on
this one. I'm on rails 2.3.2.


782b01570270ab10543bc25a258d7ea8?d=identicon&s=25 (Guest)
on 2009-04-21 15:07
(Received via mailing list)
Hi Steve,

Acutally, there are no way to do it for submit_tag & button_to, those
helpers should be totally rewritten to suport the markup you need. But
if you are building a modern unobtrusive app, then you don't really
need the functionality of those helpers, so you can just replace them
with a custom helper that just generates the markup you need.

And cusomizing the link_to is quite easy:

def cool_link_to(title, url, options = {})
  options[:class] ||= ''
  options[:class] += ' button'
  link_to(content_tag(:span, title), url, options)

<%= cool_link_to "Edit", '/edit/123', :class => 'some-other-class'
# => <a href="/edit/123" class="some-other-class button"><span>Edit</

This topic is locked and can not be replied to.