두 가지 모델이 있습니다. 일정과 프로젝트가 있습니다. belongs_To 프로젝트 및 프로젝트 has_one 일정을 예약하십시오. 일정 및 프로젝트에 대한 경로는 다음과 같이 중첩 :레일 경로에서 중첩 된 리소스로 인해 흰색 화면이 나타납니다.
get 'projects/current', to: 'projects#show_current', as: :current_freelancer_projects
resources :projects do
resources :schedules
end
내가 레이크 경로를 실행, 그것은 경로가 새로운 일정이 만들어 말한다 :
new_project_schedule GET /projects/:project_id/schedules/new(.:format)
난을 포함 할 때 문제가있다 페이지에서 new_project_Schedule 링크를 클릭하면 사파리 페이지가 흰색으로 바뀝니다. 파이어 폭스에서는 페이지가로드,하지만 난 양식의 제출 버튼을 클릭하면, 나는 오류 얻을 : 나는 양식에 대한 링크를 주석 경우
First argument in form cannot contain nil or be empty
, 나는 흰색 화면을 얻을하지 않습니다를. 여기에 링크가 있습니다 :
<% @projects.each do |project| %>
<tr>
<td><%= project.title %></td>
<td><%= project.employer.email %></td>
<td>date</td>
<td>rating</td>
<td>bid</td>
<td>tags</td>
<td><%= link_to 'Create Schedule', new_project_schedule_path(project.id) %></td>
</tr>
<% end %>
다른 모든 td 세포가 작동하기 때문에 @projects가 정의되어 있습니다. 이 문제를 어떻게 해결할 수 있습니까?
좀 더 정보 : 여기
일정 페이지의 모든 프로젝트를 표시하고 각각에 대한 링크가있는 페이지의 컨트롤러를 만들 수 있습니다 :
def show_current
@projects = current_user.projects
end
UPDATE :
여기일부 컨트롤러 :
일정 # 생성 :
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
일정 새 # :
def new #This controller is what the link above goes to
@schedule = Schedule.new
@project = Project.find(params[:project_id])
@schedule.tasks.build #tasks is a model that belongs_to schedule
end
프로젝트 #의 show_current :
def show_current #In this action view, @projects is looped through and for each project, a link to schedules#new is displayed,
@projects = current_user.projects
end
새로운 일정보기 :
<%= form_for [@project, @schedule] do |f| %>
<%= f.fields_for :tasks do |builder| %>
<%= render 'task_fields', :f => builder %>
<% end %>
<p><%= link_to_add_fields "Add task", f, :tasks %>
<p><%= f.submit "Submit" %></p>
<% end %>
UPDATE :
나는이에 LINK_TO을 변경하는 경우 :
<%= link_to 'Create Schedule', new_project_schedule_path(project.id, Schedule.where(project_id: project.id))
나는 더 이상 흰색 화면을 얻을 수 없지만 URL이 엉망 :
http://localhost:3000/projects/24/schedules/new.%23%3CActiveRecord::Relation::ActiveRecord_Relation_Schedule:0x007fa1d6422a78%3E
내가 그 URL이 될 수 없습니다 알고 바로 그래서 뭔가 내가 실제로 문제를 해결하지 않은 나에게 말한다.
는
업데이트 : 프로젝트 #의 show_current의 뷰 페이지에 대한 아무 것도 변경하면
페이지가 일시적으로 다시 작동합니다. 그러나 몇 번 새로 고침하거나 다른 페이지로 이동 한 다음 다시 돌아 가면 다시 흰색으로 변합니다. 페이지의 내용을 변경하면 일시적으로 다시 작동하고 결국 다시 흰색으로 바뀝니다. 그래서 내가 본대로, 문제는 프로젝트 # show_current 컨트롤러 또는 경로와 함께 있어야합니다. 위의 경로에 일부 노선 코드를 추가하고 있습니다. 지금은 관련성이있는 것으로 보입니다.즉, 나는 루트 코드를 변경하려고 시도했지만 아무것도 작동하지 않습니다.
__ 와우 __. 나는이 대답을 한 번 이상 투표 할 수 있었으면 좋겠다. – zeantsoi