0
也许有人可以帮助我:Rails 5.0中使用will_paginate,我读出了每页24个结果。结果取自Elasticsearch并按照_score排序。因此,无论搜索查询是什么,第一场比赛都将成为最佳匹配对象。这一切都很好。在Rails中记住使用will_paginate的值
第一个对象的得分最高,我计划显示一个相对于得分填充的进度条。因此,第一场比赛将被填充到100%,第二场比赛将(如果得分较低)填充较少。所有的作品都能找到我目前的代码。
问题:
在页1上的所有工作正常。但是,一旦我点击第2页或任何其他页面,最初的最高_分数正在丢失。而这个特定页面的第一场比赛是此后的最高分数。
我怎样才能记住最高分,而无需在控制器中运行两次查询(一次用于特定页面,一次用于检索最高分数)?
也许任何人都知道一个漂亮的伎俩来解决这个问题。
控制器
@users = current_user.search_more_like_this.paginate(:page => params[:page], :per_page => 24)
# Problem is that the highest score is recalculated once I change the page.
@highest_score = @users.first._score.to_f
查看
= link_to user_path(user.slug) do
.progressbar
%div{:style => "width: #{(user._score/@highest_score)*100}%;"}
%span{:id => "os" + user.username.to_s, :class => "slickdot"}
%span{:style => "color: white;padding-left:15px;"}
= user.username
= user._score
非常感谢你的帮助!
它是会话变量。 :D谢谢,现货! –