0

두 가지 모델이 있습니다. 일정과 프로젝트가 있습니다. belongs_To 프로젝트 및 프로젝트 has_one 일정을 예약하십시오. 몇 가지 문제가 있지만, 나는 그들 모두가 같은 원인을 가지고 있다고 생각합니다. 여기 레일은 문제를 일으키는 관계가 있습니다. 또한 흰색 화면입니다.

def create 
      @schedule = Schedule.new(schedule_params) 
      @schedule.project = Project.find(params[:project_id]) 
      if @schedule.project.student_id == current_user.id 
       if @schedule.save && @schedule.freelancer_accepts  
         flash[:notice] = "Successfully created schedule." 
         redirect_to profile_path(current_user.profile_name) 
       else 
        render :action => 'new', :notice => 'Invalid Schedule' 
       end 
      else 
       render :action => 'new', :notice => 'Schedule is invalid.' 
      end 
end 

가 문제입니다 : 다음은 일정 번호 코드가 컨트롤러를 만드는 것입니다 그것은 has_one 관계를 비록

  1. , 난 여전히 하나의 프로젝트에 대해 많은 일정을 만들 수 있어요 . 이것은이 내 컨트롤러를 변경하는 나를 인도 :

    def create 
        if !Schedule.where(project_id: params[:project_id]).any? 
         @schedule = Schedule.new(schedule_params) 
         @schedule.project = Project.find(params[:project_id]) 
         if @schedule.project.student_id == current_user.id 
          if @schedule.save && @schedule.freelancer_accepts  
            flash[:notice] = "Successfully created schedule." 
            redirect_to profile_path(current_user.profile_name) 
          else 
           render :action => 'new', :notice => 'Invalid Schedule' 
          end 
         else 
          render :action => 'new', :notice => 'Schedule is invalid.' 
         end 
        else 
         render :action => 'new', :notice => 'A schedule has already been created.' 
        end 
    end 
    

변화는 내가 본질적 스케줄이있는 경우, 하나를 만들지 않습니다 "라는 경우에 컨트롤러를 감싸이었다 내가 변경 한 후 내.

First argument in form cannot contain nil or be empty 
: 나는 새로운 일정을 만들 제출 '버튼을 누를 때, 난이 오류가, 파이어 폭스에서

  1. : 코드, 나는 다음과 같은 문제를 가지고 0

  2. Safari에서 제출 버튼을 눌러 새 일정을 만들면 페이지가 흰색으로 변합니다. 또한, 양식을 표시하는 페이지로 돌아 가려 할 때마다 페이지가 흰색으로 바뀝니다. 그것은 매우 이상합니다.

어떻게 수정합니까? 감사.

UPDATE : 내 경로와 양식보기 도움이 될 :

경로 : 형태의

resources :projects do 
    resources :schedules 
end 

첫 번째 부분 :

<%= form_for [@project, @schedule] do |f| %> 
+0

'SchedulesController # create'을 변경했다고 말한 코드는 보여준 초기 코드와 같은 것으로 보입니다. 그 차이점은 무엇입니까? –

+0

내 실수. 방금 처음에 표시 할 코드로 업데이트했습니다. – Philip7899

+0

'잘못된 일정'및 '일정이 잘못되었습니다'렌더링이 처음에 작동했는데 여전히 작동합니까? –

답변

0

이와 내가했다 가졌다 몇 가지 다른 문제를 밝혀 실제로 has_one 관계로 인한 것이 아닙니다. 내 캐시에 몇 가지 유형의 문제가있었습니다. 정확하게 무엇인지는 모르겠지만 캐시를 비활성화하여 문제를 해결할 수있었습니다.

관련 문제