2012-04-16 98 views
0

我添加了一个has_many :through协会(连接表)到我的房屋模型,因此房子可以有多重的类别,如“最后一分钟”,“房子池”等has_many:通过关联的网址/视图?

我做了一个自定义查询,因此通过例如我(5)

@lastminutes = House.find(:all, :select=>"houses.*", :joins=>"JOIN category_join_tables ON houses.id = category_join_tables.house_id", :conditions=>["category_join_tables.house_id = houses.id AND category_join_tables.category_id = ?", 5]) 

这个工作很好,在控制台。

什么是最好的方法来让我的网站工作。我想url结构像这样:

domain.com/locale/holidayhouses/lastminutes (house in the lastminute category) 
domain.com/locale/holidayhouses/holidayhouses_with_pool (houses in the pool category) 

domain.com/locale/lastminutes (houses and appartments in the lastminute category) 

任何帮助将是伟大的!

回答

1

这是很容易:

的config/routes.rb文件:

match 'search/*categories' => "controller#action" 

在你的行动,你现在得到的类别作为一个数组,只需把它解析为查询。我猜你需要“搜索”,因为否则轨道将把每一个正常的请求作为类别并将你重定向到动作。

看到How to embed multiple tags in Rails routes, like Stack Overflow


对于l18n部分,你可以不喜欢它

scope "/:locale" do 
    # move all the other routes in here to work with the locale 
end 

检查出rails guide上国际化