0

A basic question about what happens when routes are nested. I have a form that's complaining about a missing path. I'm unable to figure out how to either name the path correctly in routes, or correctly change the path it's looking for.

Here the routes:

Rails.application.routes.draw do
  resources :users do
    resources :events do
      resources :event_sessions do
        resources :locations
      end
    end
  end
end

And here's the form:

<%= form_for @event do |form| %>
...
<% end %>

The URL http://localhost:3000/users/2/events/new produces an exception:

undefined method `event_path`

What's happening here? How do I solve this?

Allan
  • 2,586
  • 5
  • 26
  • 22

1 Answers1

1

You'll have to provide the proper form_for parameter so that the form action knows how the resource is nested, for example:

<%= form_for [current_user, @event] do |form| %>
...
<% end %>
nayiaw
  • 1,416
  • 4
  • 17
  • 26