我有一个decisions
资源,它嵌套在groups
资源下。模型中已定义has_many
和belongs_to
。
resources :groups do
resources :decisions
end
...我在这条路上有一个编辑表格:
/组/:GROUP_ID /决定/:ID /编辑(:格式)
我的Rspec测试中出现错误:
失败/错误:put:update,{:id => decision.to_param,:decision => valid_attributes,group_id:decision.group.id},valid_session NoMethodError: #DecisionsController的未定义方法`decision_url':0x007ffeb23482e0>
当我在开发环境中导航到表单时,我收到类似的错误:
<%= link_to 'Edit', edit_group_decision_path(@group, @decision) %>
/ groups / 6 / decisions / 5 / edit
中的NoMethodError#&lt;#:0x007fd1ff569130&gt;
的未定义方法`decision_path'
我正在使用'better_errors'
gem,它引用了form_for
的第一行的no方法错误:
<%= form_for(@decision) do |f| %>
我的代码中没有'decision_url'
。我错过了什么? form_for
不应该知道在哪里提供更新?它有一条有效的路径:
/组/:GROUP_ID /决定/:ID(:格式)
以下是日志中最令人兴奋的部分:
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'
答案 0 :(得分:0)
这是抱怨的decision_url
来电:
if @decision.update(decision_params)
format.html { redirect_to @decision), notice: 'Decision was successfully updated.' }
将@decision
更改为group_decision_path(@group, @decision)
修复它。