我有这个HAML代码添加基于if语句的“活动”类。HAML类字符串与基于if语句的类
= link_to 'Contact Information',
edit_account_path(:contact_information),
class: ("active" if params[:section] == 'contact_information')
我想要在if语句之外永久添加一个类的字符串。
喜欢的东西
= link_to 'Contact Information',
edit_account_path(:contact_information),
class: "Tab large", ("active" if params[:section] == 'contact_information')
我需要这样做,而无需创建一个辅助方法,因为我不能给太多的编辑代码。
[在rails中使用帮助器方法将动态属性添加到HAML标记]可能的副本(http://stackoverflow.com/questions/10902377/adding-dynamic-attributes-to-haml-tag-using-helper-method- in-rails) – Iceman