Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在url/视图中是否有多个:通过关联?_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 在url/视图中是否有多个:通过关联?

Ruby on rails 在url/视图中是否有多个:通过关联?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我在我的房子模型中添加了一个has\u many:through关联(join table),这样房子就可以有多个类别,如“lastminute”、“house with pool”等 我做了一个自定义查询,所以举个例子,我希望所有房子都属于“最后一分钟”类别(5) 这在控制台中可以正常工作 在我的网站上实现这一点的最佳方法是什么。我希望url结构如下所示: domain.com/locale/holidayhouses/lastminutes (house in the lastminute

我在我的房子模型中添加了一个
has\u many:through
关联(join table),这样房子就可以有多个类别,如“lastminute”、“house with pool”等

我做了一个自定义查询,所以举个例子,我希望所有房子都属于“最后一分钟”类别(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)
任何帮助都会很好

这很容易:

config/routes.rb:

match 'search/*categories' => "controller#action"
在您的操作中,现在可以将类别作为数组获取,只需将它们解析到查询中。我想您需要“搜索”,因为否则rails会将每个普通请求作为类别,并将您重定向到操作


对于l18n部件,您可以像

scope "/:locale" do
  # move all the other routes in here to work with the locale
end
查看I18N上的

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