0

I have two lines in my routes.rb that look like this:

  resources :locations
  get '/locations/:session_series_token/new', to: 'locations#new', as: "new_location"

I want the create method in my LocationsController, and I also want a specific locations#new path.

Removing the resources :locations line causes my #new form to error with:

undefined method `locations_path' for #<<Class:0x007fa18caeb3b8>:0x007fa18caea8f0>
Extracted source (around line #1):

  <%= form_for [@location] do |form| %>
    <h2>Class Location</h2>

There must be a way to do this correctly!

Allan
  • 2,586
  • 5
  • 26
  • 22

2 Answers2

0

I think that since you are removing resources: locations there is no longer an "index" route for Location (called locations_path). Run the command rake routes and you will see that you are only left with a new_location_path.

Try specifying the path like so:

<%= form_for @location, url: new_location_path do |form| %>
Daniel Olivares
  • 544
  • 4
  • 13
0

Try this:

resources :locations, except: [:new]
get '/locations/:session_series_token/new', to: 'locations#new', as: "new_location"

As the resources :locations defines all the routes for you and you need to define only the new route explicitly so you can write like above. If you remove the resources :locations then your create route also gets removed and the line <%= form_for [@location] do |form| %> searches for the locations_path which is the create action.

Hope this helps.

Deepesh
  • 6,138
  • 1
  • 24
  • 41