Custom jQuery UI Form Rails Button Helper

jquery ui railsToday I got a little bored with my standard rails buttons

Not bad…but could use a little pizazz. So I decided to take a crack at jQuery UI. A great javascript and style framework that promised to be easy to use and provides theme-able styles.

Once you’ve got jQuery UI integrated nicely into your rails project (note i had to change my url paths in the stylesheet), you can style your submit button easily by adding some classes just like this:

Though, this isn’t 100% what I was looking for, it’s a good start. When we hover over the button, it changes color, and when we press it, our rails form submits. Though you’ll notice that the cursor doesn’t change when you hover over the button and we haven’t put an icon in it yet. To get the correct behavior i hard coded in a button:

This solved the button styling and behavior, but we still don’t have our icon. After browsing the inter webs,  I found a nice page of jQuery-UI button demos and I managed to modify my code to include a nice icon:

Perfect! It works like a dream, but it’s not very rails-esq. Lets turn this into a reusable chunk of code by making a helper method to extend form builder. In app/helpers/application_helper.rb

Read Also:  Make HTTP request using Java and Curl

Now In my View I can put:

And I get my perfectly formatted button complete with an Icon!


will print out “person”, thats why in the helper we call  self.object_name on the form_builder class. Pretty cool huh?

Leave a Reply

Your email address will not be published. Required fields are marked *