Markus
Markus

Reputation: 73

Rails url generation error on a form_for nested route and custom route

So I have two models a booker and a booking_ticket. I have nested the routes of booking_ticket under booker, but I also want to create a new booking_ticket without a booker, so I created a custom route. My action works properly when I try to create using the nested route but not on my custom path.

my routes.rb

resources :bookers do
 resources :booking_tickets
end
get '/booking_tickets/new', to: 'booking_tickets#new', as: 'new_booking_ticket'

This is the error I'm getting from rails when I use the custom path:

enter image description here

I don't understand where the error is coming from.

Upvotes: 0

Views: 99

Answers (1)

Gerry
Gerry

Reputation: 10517

You need to create a custom route for create action, your current custom resource is for new action:

post '/booking_tickets/create', to: 'booking_tickets#create'

Or, since you seem to be using defaults, just replace your current custom route with:

resources :booking_tickets, only: [:new, :create]

Be sure to add it outside resources :bookers block:

resources :bookers do
  resources :booking_tickets
end

resources :booking_tickets, only: [:new, :create]

Upvotes: 2

Related Questions