I have a decisions
resource, which is nested under a groups
resource. has_many
and belongs_to
have been defined in the models.
resources :groups do
resources :decisions
end
...and I have an edit form at this path:
/groups/:group_id/decisions/:id/edit(.:format)
I'm getting an error in my Rspec test:
Failure/Error: put :update, {:id => decision.to_param, :decision => valid_attributes, group_id: decision.group.id}, valid_session NoMethodError: undefined method `decision_url' for #DecisionsController:0x007ffeb23482e0>
And when I navigate to the form in my development environment, I get a similar error:
<%= link_to 'Edit', edit_group_decision_path(@group, @decision) %>
NoMethodError at /groups/6/decisions/5/edit
undefined method `decision_path' for #<#:0x007fd1ff569130>
I'm using the 'better_errors'
gem, and it cites the first line of the form_for
for the no method error:
<%= form_for(@decision) do |f| %>
I don't have 'decision_url'
anywhere in my code. What am I missing? Shouldn't form_for
know where to PUT the update? There's a valid path for it at:
/groups/:group_id/decisions/:id(.:format)
Here is the part of the log that looks most exciting:
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'
This is the decision_url
call that it was complaining about:
if @decision.update(decision_params)
format.html { redirect_to @decision), notice: 'Decision was successfully updated.' }
Changing @decision
to group_decision_path(@group, @decision)
fixed it.