I’m in the process of creating voting links (thumbs up, thumbs down, favorite etc).
I’ve been using RESTful rails routes and I’m comfortable using link_to for just about everything, including not-GET requests. link_to is easier to style than button_to since button_to brings in a an entire form with an input of type submit, which always seemed heavier than doing just link_to with :method => :delete or :method => :post. The only time I use a form is when I need to collect data from the user, and I never use button_to.
I went to youtube to see how they style their voting buttons, and they actually use buttons.
<button onclick=";return false;" title="I dislike this" type="button" class="end yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip yt-uix-button-empty" id="watch-unlike" data-button-action="yt.www.watch.actions.unlike" role="button" data-tooltip-text="I dislike this">
<img class="yt-uix-button-icon yt-uix-button-icon-watch-unlike" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt="">
</button>
From this snippet it looks like they are using the button merely as a container for an image sprite. The button is not surrounded by form tags so I’m guessing there is unobtrusive js that triggers an HTTP POST elsewhere.
Youtube is owned by google, so I guess the way they are doing it must be the best practice, yes?
There is no railsy way that I know of doing a button without the form, short of writing the button tag directly, which always make me think twice when I’m about to do something that rails doesn’t already provide me.
So my question is, what is the technical advantage (if any) of doing it the youtube way?
Its all about degrading gracefully
The simple link won’t post a form without javascript.
(Ok it’s not all about that, its also semantics, eg compatibility for page-readers for people with disabilities etc)