简体   繁体   English

Rails 3:Merit Gem通过下拉按钮按季节显示记录

[英]Rails 3: Merit Gem to show records by seasons through dropdown button

class StaticPagesController < ApplicationController
 def home

 end

 def leaderboard
   @scores = Merit::Score.top_scored
 end
end

I am using the merit system for my ruby on rails application and i want to show records by seasons (Summer, Fall, Winter) through an action of a button. 我正在将红宝石功能应用到我的Rails红宝石应用程序中,我想通过一个按钮操作按季节(夏季,秋季,冬季)显示记录。

New to rails and first time I've ran into an occasion where I can't find the answer already posted online. 第一次接触Rails时,我遇到了无法找到已经在线发布的答案的情况。

Using this code here for the leaderboard: https://github.com/tute/merit/wiki/How-to-show-a-points-leaderboard 在此处使用此代码排行榜: https : //github.com/tute/merit/wiki/How-to-show-a-points-leaderboard

I solved the issue by using this code in my static page controller: 我通过在静态页面控制器中使用以下代码解决了该问题:

def leaderboard
since_date = params[:since_date]
end_date = params[:end_date]
  if since_date.blank? && end_date.blank?
      @scores = Merit::Score.top_scored
  else
      @scores = Merit::Score.top_scored(since_date: since_date, end_date: end_date)
end

and creating an end date in top scored. 并在得分最高的位置创建结束日期。 Then passing the params within the link. 然后在链接内传递参数。

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

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