未定义的方法在哪里调用?

时间:2015-08-25 00:10:14

标签: ruby-on-rails ruby ruby-on-rails-4 better-errors-gem

我有一个decisions资源,它嵌套在groups资源下。模型中已定义has_manybelongs_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'

1 个答案:

答案 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)修复它。