带有单独搜索屏幕的 Restful URL
我们正在考虑让我们的 URL 方案变得更加平静,并且在大多数情况下这对我们来说是有意义的。我们找不到很好的例子的一件事是如何处理单独的搜索屏幕?我们需要向用户显示卡片列表,但他们始终需要先进行搜索。
有什么想法或例子吗?
We're looking at going a little more restful in our URL scheme and for the most part it make sense to us. The one thing we can't find a good example of is how do you handle a separate search screen? We need to show a list of cards to the user but they always need to do a search first.
Any ideas or examples out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将搜索视为 RESTful 资源...
Ryan Bates 在此解释了该模式:http:// railscasts.com/episodes/111-advanced-search-form
这符合要求吗?
You can treat Search as RESTful resource ...
Ryan Bates explains the pattern here: http://railscasts.com/episodes/111-advanced-search-form
This fit the bill?
我会在我的模型类中设置一个范围来执行您想要的搜索;只需将 lambda 添加到范围中,以便您可以传递搜索词,应该看起来像这样:
然后在控制器的索引中,只需检查请求参数(无论您命名它)并在那里执行适当的操作
I'd set up a scope in in my model class that does the search you want; just add a lambda to the scope so you can pass in the search term, should look something like this:
and then in your controller's index, just check for the request param (whatever you're naming it) and do the appropriate thing there