/ Published in: Ruby
This very simple but useful helper lets you putting some particular class tag to an html entity in case of coincidence of two arguments given. This case is very usual when building rhtml code and quite painful for programming it at the ERB. The most normal use is for
Expand |
Embed | Plain Text
Helper: def class_if_match (class_id, arg_1, arg_2) if arg_1 == arg_2 return 'class="' + class_id + '"' else return nil end end Example rhtml file: <li <%= class_if_match ('active-item', item, @active_item) %>> the item </li> css file: .active-item { font-weight: bold; }
You need to login to post a comment.
