2014-01-09 2 views
1

등록 컨트롤러의 업데이트 작업에이 코드가 있습니다. 그리고 정의되지 않은 메소드 'errors'을 얻습니다. 여기에 플래시 메시지를 사용할 수 없습니다.정의되지 않은 메소드`errors '

if subjects_selected.blank? 
     @registration = Registration.where(:student_id => params[:registration][:student_id], :semester_id => params[:registration][:semester_id]) 
     redirect_to editreg_registrations_path(@registration.first.id, params[:registration][:student_id], params[:registration][:semester_id]), @registration.errors.add(:You_have_to_register_for_at_least_one_subject) and return 
    end 

어떻게 오류 방법에 액세스 할 수 있습니까?

+0

당신이 당신의 전체 오류 스택을 게시 할 수 등록 모델에

error_array = Registration.validate_subjects(params[:registration][:student_id],params[:registration][:semester_id]) 

같은 오류를 표시 오류에 대한 등록 모델의 방법을 취할 수 있습니다.? – Pavan

답변

0
if subjects_selected.blank? 
    @registration = Registration.where(:student_id => params[:registration][:student_id], :semester_id => params[:registration][:semester_id]) 

    if [email protected]  
    redirect_to editreg_registrations_path(@registration.first.id, params[:registration][:student_id], params[:registration][:semester_id]) 
    else 
    @registration.errors.add(:You_have_to_register_for_at_least_one_subject) 
    end 

end 
1

당신은 다음

def validate_subjects(student_id, semester_id) 
is_registration = self.where(:student_id=>student_id,:semester_id =>semester_id) 
error_array=[] 
if !is_registration 
//RIGHT THE CODE 
error_array << "You_have_to_register_for_at_least_one_subjec" 
end 
error_array 
end 
관련 문제