Better HTML forms in Ruby on Rails

One of the interesting things about working with the built-in conventions in Ruby on Rails is the way it gets me thinking about what other conventions I can come up with to make things even easier.

Form Style Helper is a Rails helper module that overrides the standard form helpers in order to add helpful CSS classes to your form elements for easier styling. Now you can more easily differentiate between input fields and buttons, radio buttons and checkboxes, and everything else. All standard form helpers are supported.

Usage

Install form_style_helper.rb in your Rails application's helpers directory (app/helpers/) and include it at the top of your main ApplicationHelper:


include FormStyleHelper

This makes it available to all views in your application. Now just continue using your form helper methods as usual and the CSS classes will automatically be added to each element. So now this:


<%= text_field_tag "name" %>

Will give you this:


<input class="text_field" id="name" name="name" type="text" />

Download

Download Form Style Helper from Github

License

Form Style Helper is released under the terms of the MIT License and is free to use and redistribute for any purpose. If you find this code helpful, a link back to my site would be cool, but it’s not required.