다음 시나리오에 대한 사용자 지정 유효성 검사를 만들어야하는지 궁금합니다.레코드가 모델 레일에 있는지 확인하십시오.
사용자가 축구 경기 세트에 대한 예상 점수를 제출하는 예측 모델은 fixture_date별로 그룹화되어 있습니다.
사용자가 이미이 게임에 대한 예상 검색어를 제출 한 경우 오류가있을 때 제출할 수 없다는 오류 메시지가 표시되거나 날짜에 대한 예측이 존재하는 경우 양식이 표시되지 않을 수 있습니다. 순간 나는 같은 게임에 대해 여러 세트의 예측을 만들 수 있습니다. 아마 유효성 검사가 더 좋을 것입니다. current_user의 해당 날짜에 대한 예측이 존재하면 제출하지 말라는 것에 대해 어떻게 생각합니까?
그래서 내 설정은 다음과 같습니다 지금까지의 예측과 게임 사이의 관계에 대해 확실하지class Prediction < ActiveRecord::Base
attr_accessible :home_team, :away_team, :home_score, :away_score, :fixture_date, :fixture_id, :user_id
has_one :fixture
end
class Fixture < ActiveRecord::Base
attr_accessible :home_team, :away_team, :fixture_date, :kickoff_time, :prediction_id
end
예측 컨트롤러
def index
@predictions = current_user.predictions if current_user.predictions
end
def new
@prediction = Prediction.new
end
def create
begin
params[:predictions].each do |prediction|
Prediction.new(prediction).save!
end
redirect_to root_path, :notice => 'Predictions Submitted Successfully'
rescue
render 'new'
end
end
end
당신의 조명기 모델에서 belongs_to : prediction을 잊었습니다. 아마도이 오류가 발생합니다. – Mattherick