Reputation: 1080
@reckoner has_many @shift_requirements and in routes,
resources :reckoners do
resources :shift_requirements
end
In a view under reckoner_controller.rb I have
<%= link_to 'create a shift', [:new, @reckoner, :shift_requirement]%>
... which fires the correct view containing a form helper. Then it throws the error -
undefined method `shift_requirements_path' for #<#<Class:0x007f908e00a458>:0x007f908e8a09c8>
How have I gone wrong?
shift_requirement.rb is -
class ShiftRequirement < ActiveRecord::Base
belongs_to :reckoner
end
reckoner.rb is -
class Reckoner < ActiveRecord::Base
has_many :shift_requirements
end
... and the view in the form is now
<%= form_for(@reckoner, @shift_requirement) do |f| %>
...
<%= f.submit %>
Upvotes: 0
Views: 166
Reputation: 10406
I assume your form has:
<%= form_for(@shift_requirement) do |f| %>
<%= f.submit %>
<% end %>
Because of your nested routes you want
<%= form_for([@reckoner, @shift_requirement]) do |f| %>
<%= f.submit %>
<% end %>
Upvotes: 1