2017-02-12 5 views
1

내 new.html.erb 페이지에서 양식을 만들려고하는데 정의되지 않은 메서드 인 'task_presentations_path'오류가 발생했습니다.다형성 연관을 사용하여 양식을 사용하는 방법

= form_tag [@task, Presentation.new] do |f| 
    = f.label :summary 
    = f.text_field :summary 

tasks_controller

def new 
    @task = Task.new 
end 

루트

resources :presentations do 
     resources :tasks 
    end 

작업 모델

class Task < ApplicationRecord 
    belongs_to :taskable, polymorphic: true 
    has_one :task_type 
    has_one :task_status 
end 

프리젠 테이션 모델

,
class Presentation < ApplicationRecord 
    has_many :tasks, as: :taskable 
end 

레이크 작업

당신의 task 모델로
  presentation_tasks GET  /presentations/:presentation_id/tasks(.:format)    tasks#index 
          POST  /presentations/:presentation_id/tasks(.:format)    tasks#create 
     new_presentation_task GET  /presentations/:presentation_id/tasks/new(.:format)   tasks#new 
     edit_presentation_task GET  /presentations/:presentation_id/tasks/:id/edit(.:format)  tasks#edit 
      presentation_task GET  /presentations/:presentation_id/tasks/:id(.:format)   tasks#show 
          PATCH /presentations/:presentation_id/tasks/:id(.:format)   tasks#update 
          PUT  /presentations/:presentation_id/tasks/:id(.:format)   tasks#update 
          DELETE /presentations/:presentation_id/tasks/:id(.:format)   tasks#destroy 
+0

나는'bundle exec rake routes | grep task'를 실행하고 그 경로가 무엇인지 확인하십시오. 보이는 것처럼 그것은 presentation_tasks_path 수 있지만 확실하지 않아요 – mccalljt

+0

컨트롤러 및 모델에 대한 자세한 정보를 추가 할 수 있습니까 ..? – Milind

+0

예 업데이트했습니다. – brandoncodes

답변

0

presentationnested 자원, presentation 모델 present.So이다있을 때 존재하는 경우에만해야 원래입니다 ...

######in the controller. 

def new 
    @presentation = Presentation.find(params[:id) 
    @task = @presentation.tasks.new 
end 

#####in your view 
= form_tag [@presentation,@task] do |f| 
    .... 
    .... 

호프가 도움이 되길 바랍니다.

+0

실제로 나는 그것을 시도했습니다. 내가 할 때, 내가 얻을 오류가 정의 된 메서드'tasks_path '양식에 – brandoncodes

+0

양식을 변경 params ... 나는 내 대답을 업데이 트했습니다. 프레젠테이션/작업 ... 프레젠테이션을 먼저 전달한 다음 양식에 작업을 전달해야합니다. 내 대답을 확인하십시오. 작동하는지 알려주십시오. :) – Milind

+0

감사합니다! :) 그것은 작동하지 않습니다. 그러나 지금 내가 얻는 오류는 레이블에 정의되지 않은 메서드 인 label for nil이 있습니다. NilClass – brandoncodes