I added a has_many :through association (join table) to my houses model, so a house can have multiply categories such as “lastminute”, “house with pool” etc.
I made a custom query, so by example I want all the house in the “lastminute” category (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])
This work fine in the console.
What is the best approach to get this working on my site. I want url stucture likes this:
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)
Any help would be great!
It is quite easy:
config/routes.rb:
In your action you get now the categories as an array and only need to parse them into the query. I guess you need the “search” because otherwise rails will take every normal request as categories and redirect you to the action.
see How to embed multiple tags in Rails routes, like Stack Overflow
For the l18n part you can do it like
check out the rails guide on I18N