views:

29

answers:

2

I'm starting to use the jQuery UI CSS Framework for an app, which means I have to start adding classes to everything. So, for example, I want to make all buttons jQuery-themed, which means adding a class to all buttons.

I imagine there's some way in Rails to modify the helpers so I don't have to manually add a :class => 'blah' to every button, but I can't work it out. Is this possible, or does anybody have any better ideas?

+1  A: 

Why not use jquery, somthing like:

$('button').attr('class', 'blah');
Tim
That's not a bad idea actually. There must be a simple way to do this in Rails though, surely.
Skilldrick
I've done some more reading and it looks like this may be the most sensible answer - it doesn't look like a simple task to override helper methods. I'll mark this accepted unless I get a Rails-based solution today.
Skilldrick
I actually went this route in the end - the helper way had too many edge cases, and I'm not writing all my HTML with helpers anyway. The jQuery way keeps it all in one place with one technique. I don't really feel like I can mark this as the accepted answer though, because the other one answers the question I actually asked. But thanks anyway!
Skilldrick
That's cool. I got 10 points, so I'm happy :)
Tim
+2  A: 

You just need override the helper method with this class add. In your application_helper.rb

  def button_to(name, options = {}, html_options = {})
    super(name, options, html_options.merge(:class => 'blah'))
  end
shingara
Looks a bit recursive to me...
Skilldrick
yes, use super instead. I edit my answer
shingara
Great, that's what I was looking for - thanks!
Skilldrick