我正在尝试遍历我的日程表并使用“日期时间:> = Time.now”获取一条记录,以显示下一场比赛的当前球队。
这是我的团队模型:
class Team < ActiveRecord::Base
attr_accessible :city, :conf, :div, :full_name, :name, :short_name
has_many :fans
has_many :away_schedules, class_name: 'Schedule', foreign_key: :away_team_id
has_many :home_schedules, class_name: 'Schedule', foreign_key: :home_team_id
def schedules
(away_schedules + home_schedules).sort_by(&:id)
end
end
这是我的计划模型:
class Schedule < ActiveRecord::Base
attr_accessible :away_team_id, :datetime, :home_team_id, :season, :week
belongs_to :away_team, class_name: 'Team'
belongs_to :home_team, class_name: 'Team'
end
我有一个 games_helper.rb
module GamesHelper
def current_game
@current_game = current_fan.team.schedules
end
end
我有部分 _scoreboard.html.erb
<% current_game.each do |game| %>
<% if game.datetime.to_s >= Time.now.to_s %>
<% return current_game = game.datetime.to_s(:custom),
game.away_team.short_name, " @ ", game.home_team.short_name %>
<% end %>
<% end %>
这似乎可行,但使用 return 将数组放在结果周围的括号中:
["Sun, Sep 15th, at 4:25 PM", "DEN", " @ ", "NYG"]
希望它显示:
Sun, Sep 15th, at 4:25 PM, DEN @ NYG
我不确定我是否以正确的方式解决这个问题。