それで、移行ファイルを作成して移行し、「プレーヤー」クラスを作成しました。私はこのコードを実行しようとしています:
def get_most_recent_ladder
@top_80 = Team.all
# loop through all teams, add each player and their rating to the hash, sort by rating, limit to 200
all_players = []
@top_80.each do |team|
url = "http://modules.ussquash.com/ssm/pages/leagues/Team_Information.asp?id=#{team.team_id}"
doc = Nokogiri::HTML(open(url))
player_names = doc.css('.table.table-bordered.table-striped.table-condensed')[1].css('tr td a').map(&:content)
player_ratings = doc.css('.table.table-bordered.table-striped.table-condensed')[1].css('tr td:nth-child(4)').map(&:content)
for i in (0..player_names.length-1)
player = Player.create(player_names[i], player_ratings[i].to_f, team.name)
all_players << player
end
end
all_players = all_players.sort{|player1, player2| player1.rating <=> player2.rating}.reverse.first(200)
#insert creation of ladder object with order
@ladder = all_players
render 'ladder'
end
残念ながら、コードを実行すると、Rails は「間違った数の引数 (0..2 に対して 3)」を返します。
1) これが私の Player クラスです:
class Player < ActiveRecord::Base
attr_accessible :name, :rating, :team
end
したがって、Player クラスの新しいインスタンスを作成するには、3 つの引数が必要です。
2) 通常の整数ではなく「0..2」と表示される理由がわかりません。
3) また、「未初期化定数 PagesController::Player.
私が使用しているHAMLレイアウトは次のとおりです。
#ladder
%tr
%th Player
%th Rating
%th Team
%tr
-@ladder.each do |player|
%td player.name
%td player.rating
%td player.team
何らかの理由で、私の見出しを出力しますが、各プレイヤーの実際の名前、評価、およびチームの代わりに、文字通り「player.name」、「player.rating」、「player.team」を何度も出力します...
考え?
かなり混乱しているので、どんな助けも素晴らしいでしょう!
ありがとう、マリオグ