我想在我的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
rake任務
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
我會運行'bundle exec rake routes | grep任務「並查看該路由被調用的內容。看起來像它可能是presentation_tasks_path,但我不確定 – mccalljt
你可以添加控制器和模型的更多信息..? – Milind
是的,我已更新。 – brandoncodes