2017-02-12 14 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 

すくいタスク

  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

あなたtaskモデルが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 'はnilです:NilClass – brandoncodes

関連する問題