繁体   English   中英

Rails:根据网址显示搜索结果

[英]Rails: Show search results based on url

我正在使用“ mongoid_search”在我的应用程序的索引页面上进行搜索。

返回结果的URL类似于:“ / profiles?utf8 =✓&profile_search = San + Antonio%2C + TX”

我将如何让/ location / sanantonio-tx返回与搜索网址相同的结果?

基本上,“ location”之后的所有内容都应转换为“ profile_search”查询字符串。

另外,是否可以保持URL相同? (例如:“ / location'san-antonio-tx” URL不会更改为查询字符串)

查看您提供的代码,似乎搜索是在“配置文件”控制器的“索引”操作中执行的。 在这种情况下,您可以创建一个新路线:

#config/routes.rb
match '/location/:profile_search' => 'profiles#index'

这将调用“配置文件”控制器的“索引”操作,同时将网址的“ / location /”部分之后的所有内容作为名为“ profile_search”的参数提供

有关更多信息: http : //guides.rubyonrails.org/routing.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM