0

I have nested resources, and I'm trying to create form partials for each individual resource to use for the new and edit action of each.

routes.rb

resources :accounts, shallow: true,   :except => [ :destroy ] do
  resources :service,                 :except => [ :destroy ]
end

If I use the following in the form partial, the edit form renders correctly and saves updates correctly, but the new form fails to render with the error undefined method services_path

/app/views/services/_service_form.html.erb

<%= simple_form_for @service do |f| %>

If I use the following in the form partial, the new form renders correctly and saves the object correctly, but the edit form fails to render with the error undefined method account_service_path

/app/views/services/_service_form.html.erb

<%= simple_form_for [@account, @service] do |f| %>

I've tried adding url: service_path(@service) to both versions of the form block declaration as shown, but it doesn't solve either problem.

There's bound to be something obvious I'm missing with getting this working, I'm sure I've had nested resources working correctly with a single form partial in the past, I just can't see what's different this time.

bdx
  • 3,316
  • 4
  • 32
  • 65
  • Possible duplicate: http://stackoverflow.com/questions/9772588/when-using-shallow-routes-different-routes-require-different-form-for-arguments – ramblex Mar 29 '13 at 11:30
  • Do you set the @account variable in your edit action? I think it should work with `<%= simple_form_for [@account, @service] do |f| %>` if @account is set by for example `@account = @service.account`. – Arjan Mar 29 '13 at 11:33

1 Answers1

0

Change your code to following change :service to :services

Given your Account Model has_many :services and Service Model have belongs_to : account

resources :accounts, shallow: true,   :except => [ :destroy ] do
  resources :services,                :except => [ :destroy ]
end
Pramod Shinde
  • 1,802
  • 1
  • 15
  • 28