그래서 마이그레이션 파일을 생성하고 마이그레이션 한 다음 "Player"클래스를 작성했습니다. .RoR 앱에서 잘못된 인수 수가 잘못 되었습니까? 확실하지 않은 이유
: 나는이 코드를 실행하면 레일이 나에게 인수 "잘못된 번호 (0..2 3) 그래서 몇 가지를 제공합니다, 불행하게도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
:이 코드를 실행하기 위해 노력하고있어
class Player < ActiveRecord::Base
attr_accessible :name, :rating, :team
end
은 그래서 플레이어 클래스의 새 인스턴스를 만들 수 3 개 인수를 필요로한다은 "0..2을 표시 이유를 모르겠어요
2) :
1) 여기 내 플레이어 클래스입니다. "정상적인 정수 대신.
3) 또한, "Uninitialized Constant PagesController :: Player.
여기 내가 사용하고있어 HAML 레이아웃입니다 : 어떤 이유
#ladder
%tr
%th Player
%th Rating
%th Team
%tr
[email protected] do |player|
%td player.name
%td player.rating
%td player.team
, 내 제목을 출력,하지만 말 그대로 "player.name", "player.rating", "플레이어를 출력합니다. 팀 "을 각 선수의 실제 이름, 등급 및 팀 대신 반복해서 표시합니다.
생각 하시겠습니까?
꽤 혼란스러워서 도움이 될 것 같습니다.
감사합니다, Mariogs
은'0..2' 문제의 방법은 당신에게 0 ~ 2 인수를 기대하지만되었음을 의미 3을 제공했다. –
또한, "초기화되지 않은 상수 에러"오류를주는 이유는 아마'rails c '대신'irb'를 실행했기 때문일 것이다. – jamby