开发者

Modifying Rails helpers to add HTML classes

开发者 https://www.devze.com 2023-01-17 23:04 出处:网络
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 c

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 开发者_JAVA百科possible, or does anybody have any better ideas?


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


Why not use jquery, somthing like:

$('button').attr('class', 'blah');
0

精彩评论

暂无评论...
验证码 换一张
取 消