思考狮身人面像显示选项
好的,我有一个图形模型,并且我使用思考狮身人面像作为搜索工具。它工作得很好,但我想在搜索结果页面上显示不同的模型。例如,
我在我的图形模型中有这个,
define_index do
indexes :name, :description, :scale,
indexes sub_category.name, :as => :subcategory_name
indexes sub_category.category.name, :as => :category_name
indexes colors.name, :as => :color_name
end
这很好,但问题是我想显示找到的搜索的所有类别和子类别,而不是只是相关的图形。在我的控制器中,我应该有三个这样的发现,
@graphics = Graphic.search params[:search]
@categories = Categories.search params[:search]
@sub_categories = SubCategories.search params[:search]
这似乎有点矫枉过正...有没有更好的方法,以便在视图中我可以单独显示它们
Ok so i have a graphic model and I am using thinking sphinx as the search tool. It works well but i want to display different models on the search results page.. for example
i have this in my Graphic model
define_index do
indexes :name, :description, :scale,
indexes sub_category.name, :as => :subcategory_name
indexes sub_category.category.name, :as => :category_name
indexes colors.name, :as => :color_name
end
This is fine and good but the problem is i want to display all the categories and subcategories for a found search and not just the graphics that are related. In my controller should i have three find like
@graphics = Graphic.search params[:search]
@categories = Categories.search params[:search]
@sub_categories = SubCategories.search params[:search]
this seems like overkill...is there a better way so in the view i can show each of them seperately
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要在类别和子类别模型中定义索引,然后您可以同时搜索所有三个模型:
在您看来,您需要围绕每个搜索结果使用一些逻辑来呈现正确的 HTML - 也许您每个班级可以有不同的部分吗?我还建议将其包装到一个助手中。这是一个开始:
帮助者:
希望这能为您提供一些如何解决问题的想法。
You'll need to have indexes defined in your Category and SubCategory models as well, and then you can search across all three at once:
In your view, you'll want some logic around each search result to render the correct HTML - perhaps you can have different partials for each class? I'd also recommend wrapping it into a helper. Here's a start:
And the helper:
Hopefully this gives you some ideas on how to approach the problem.
只是为了缩短示例,您可以这样做:
控制器中
在视图中的
应该调用每个模型部分“graphic/_graphic.html.erb”、“categories/_category.html.erb”等
Just to shorten example you can do:
in controller
in view
should call every model partial 'graphic/_graphic.html.erb', 'categories/_category.html.erb' and so on