I'm a Rails noob, and am looking for assistance in clearing the results of a search.
我是一个Rails noob,我正在寻找帮助清除搜索结果。
I've built a sample application which lists cafes, and have implemented searching using elasticsearch and searchkick. The search function appends parameters to the URL as in http://localhost:3000/cafes?search=sydney&commit=Search and is working correctly.
我已经构建了一个列出咖啡馆的示例应用程序,并使用elasticsearch和searchkick实现了搜索。搜索功能将参数附加到URL,如http:// localhost:3000 / cafes?search = sydney&commit = Search,并且工作正常。
Now I'd like to add a button to clear the search results:
现在我想添加一个按钮来清除搜索结果:
The Clear button's link is to the cafes_path
(http://localhost:3000/cafes), so it basically reloads the page without the search parameters:
Clear按钮的链接是cafes_path(http:// localhost:3000 / cafes),因此它基本上重新加载没有搜索参数的页面:
= form_tag cafes_path, :method => :get do
= text_field_tag :search
= submit_tag value = "Search"
= link_to cafes_path
- Is that an acceptable way to clear the search?
- Is it an acceptable Rails approach to use JavaScript logic to enable/disable the Clear button, based on what's in the search box?
这是清除搜索的可接受方式吗?
根据搜索框中的内容,使用JavaScript逻辑启用/禁用“清除”按钮是否是可接受的Rails方法?
Please let me know if you need to see more of the model or controller code to make sense of the question.
如果您需要查看更多模型或控制器代码以了解问题,请告诉我。
1 个解决方案
#1
- This way is pretty standard
- sure, use javascript - or you can also google for other ways it's been done and see what they did.
这种方式很标准
当然,使用javascript - 或者你也可以google以其他方式完成它并看看它们做了什么。
#1
- This way is pretty standard
- sure, use javascript - or you can also google for other ways it's been done and see what they did.
这种方式很标准
当然,使用javascript - 或者你也可以google以其他方式完成它并看看它们做了什么。