I don’t see why ‘class’ would get the special treatment when all other attributes could be candidates too and that style is very inconsistent with pretty much all of rails and not particularly clear either.
I personally just use a helper if logic is required for attributes.
Well this is old, but still relevant I’ve seen the replies, but i’ve we do it the way we wanted and just because all the other attributes are doing it that way, i think you’re doing it wrong. Rails is meant to please the developer, making painful constructs just to make a link selected or current is just crazy.
I’d would love it if rails would have a class: {selected: selected?, btn: true}
Rails, is elegant, makes sense and just works. Some hashes get special treatment, thats fine.
Rather than alter all the individual helper methods which take a :class option (e.g. link_to, content_tag), why not just use a helper method to generate the finalized list of classes?