我有一个decisions
资源,它嵌套在一个groups
资源下。has_many
并belongs_to
已在模型中定义。
resources :groups do
resources :decisions
end
...我在这条路径上有一个编辑表单:
/groups/:group_id/decisions/:id/edit(.:format)
我的 Rspec 测试出现错误:
失败/错误:put :update, {:id => decision.to_param, :decision => valid_attributes, group_id: decision.group.id}, valid_session NoMethodError: undefined method `decision_url' for #DecisionsController:0x007ffeb23482e0>
当我在开发环境中导航到表单时,我收到了类似的错误:
<%= link_to 'Edit', edit_group_decision_path(@group, @decision) %>
/groups/6/decisions/5/edit 处的 NoMethodError
#<#:0x007fd1ff569130> 的未定义方法“decision_path”
我正在使用'better_errors'
gem,它引用了form_for
no 方法错误的第一行:
<%= form_for(@decision) do |f| %>
我的代码中没有'decision_url'
任何内容。我错过了什么?不应该form_for
知道将更新放在哪里?它有一个有效的路径:
/groups/:group_id/decisions/:id(.:format)
以下是日志中看起来最令人兴奋的部分:
Rendered decisions/_form.html.erb (6.5ms)
Rendered decisions/edit.html.erb within layouts/application (7.1ms)
Completed 500 Internal Server Error in 9ms (ActiveRecord: 0.1ms)
NoMethodError - undefined method `decision_path' for #<#<Class:0x007fd5d98527b0>:0x007fd5d400d618>:
actionpack (4.2.3) lib/action_dispatch/routing/polymorphic_routes.rb:220:in `polymorphic_method'
actionpack (4.2.3) lib/action_dispatch/routing/polymorphic_routes.rb:134:in `polymorphic_path'
actionview (4.2.3) lib/action_view/helpers/form_helper.rb:466:in `apply_form_for_options!'
actionview (4.2.3) lib/action_view/helpers/form_helper.rb:434:in `form_for'