嵌套的资源,这是我的房子模型与过滤
has_many :taggings
has_many :tags, through: :taggings
def self.tagged_with(name)
Tag.find_by_name!(name).houses
end
end
这是我的房子控制器
def index
if params[:tag]
@houses = House.tagged_with(params[:tag])
end
end
观点:
- @houses.each do |house|
ect
这工作得很好......这滤掉带有当前标签的房屋,像这样/ house/tag/tagname
但我实现了嵌套资源,所以我需要将我的视图更改为此。
- @regions.each do |region|
- region.houses.find_all do |house|
如何在新视图中使用过滤器标签?我以为这
- @regions.each do |region|
- region.houses.find_tagged_with(params[:tags]) do |house|
但这不会工作...请帮助。
它..工作...你是男人! – Remco 2013-04-23 09:36:58