导轨 - 使用哈希
问题描述:
我试图使用条件语句这content_tag
哈希里面,这样,当'hdrs'
包括'fields'
内的任何值,则:class=>'foo'
将被设置为:class=>'bar'
内部条件语句。是否有可能在content_tag
散列中加入内联条件?如果是这样,怎么样?导轨 - 使用哈希
fields = ['name']
headers.collect { |hdrs| content_tag('th', hdrs, {:nowrap=>true, :class=>'foo', :name=>hdrs}) }
答
headers.collect { |hdrs| content_tag('th', hdrs, {:nowrap=>true, :class=>(fields.include?(hdrs) ? 'bar' : 'foo'), :name=>hdrs}) }
+0
你达人纳仁! – oprogfrogo 2011-04-20 18:33:22
你为什么不打电话跟内部的逻辑的另一种方法? – apneadiving 2011-04-20 17:58:47