【发布时间】:2017-02-12 23:41:14
【问题描述】:
我正在尝试在我的 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
【问题讨论】:
-
我会运行
bundle exec rake routes | grep task并查看该路线的名称。看起来可能是presentation_tasks_path,但我不确定 -
你能补充更多控制器和型号的信息吗..?
-
是的,我已经更新了。
标签: ruby-on-rails forms erb polymorphic-associations