0

这是我家模型的一部分。如何获取我的HAML模板中的关系数据值

class House < ActiveRecord::Base 

    has_many :amenity_appartment 
    has_many :amenities, :through => :amenity_appartment 

    has_many :category_join_table 
    has_many :categories, :through => :category_join_table 

    has_one :price 
end 

因为我们在我们的房源中有超过100间房屋,我想添加过滤功能。搜索后,我找到了很好的方式来做到这一点。 http://www.webegg.co.uk/jquery-multiple-filter/

我要开始与3过滤选项...价格,类别(国家,维拉ECT)和的amenties(洗碗机,beertap ECT)

我只需要填写我的模板与数据价值我的房子关系。

例子:

#holderwrap 
    %ul#holder.filterThis 
    %li.1200.design-villa.dishwasher.barbecue.wifi 

(1200每周欧元 - 别墅设计与设施,洗碗机,烧烤和wifi)

我怎样才能填补了LI标记值是多少?

回答

2

在HAML,你可以在哈希通过HTML类:

%li{ :class => "1200 design-villa dishwasher barbecue wifi" } 

您将需要获得舒适的名字,并将其转化为各自的HTML类(如有必要),并加入到一个字符串。你也许可以打包这一切都成House实例方法:

def features_to_html_class 
    "#{price} #{(amenities + categories).map(&:name).join(' ')}" 
end 

而在你的看法:

%li{ :class => house.features_to_html_class }