Today I got a little bored with my standard rails buttons
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:
[crayon-5bca5bd69ec45277486179/] 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:
[crayon-5bca5bd69ec50643407437/] 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:
[crayon-5bca5bd69ec54206754459/] 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
[crayon-5bca5bd69ec58518967321/] Now In my View I can put:
[crayon-5bca5bd69ec5b810830759/] And I get my perfectly formatted button complete with an Icon!
[crayon-5bca5bd69ec5f700735338/] will print out “person”, thats why in the helper we call self.object_name on the form_builder class. Pretty cool huh?