0

In my project I have a class called City and I have created the aliases BirthCity and ResidenceCity. I want to change the routes.rb file in the correct way.

I've tried adding

resources :birth_cities,  :path => :cities, as: => :cities 
resources :residence_cities,  :path => :cities, as: => :cities 

Every time I call birth_city_path, I want it to be referenced to city_path. But I'm getting the following error:

syntax error, unexpected => (SyntaxError)
...ties,  :path => :cities, as: => :cities 
...                             ^~

Any ideas? I've also tried modified it like this:

resources :birth_cities,:path => :cities,:as 'cities' 

but it doesn't work anyway.

EDIT: now the sintax is corret but I'm getting another error

undefined method `birth_cities_path' for #<#<Class:0x00007f4b3cfcd6c0>:0x00007f4b21303950>

for the following line

<%= guiFieldAutocomplete(f, :birth_city_id, { data: { autocomplete_source: birth_cities_path(col: "json_recordset_name") }}) %>
Silvia G.
  • 1
  • 3

2 Answers2

0
as: => :cities 

should be

:as => :cities 

syntax for hash literals

{ :a => 3, "b" => 4 }

new syntax for hash literals with symbol keys

{ a: 3, b: 4 }

this is equals to

{ :a => 3, :b => 4 }

just shorter

you're kinda mixing these two syntaxes

Ursus
  • 29,643
  • 3
  • 33
  • 50
0

It seems like you are confused between new and old hash syntax.

You should replace this code:

resources :birth_cities,  :path => :cities, as: => :cities
resources :residence_cities,  :path => :cities, as: => :cities 

with

resources :birth_cities,  :path => :cities, :as => :cities
resources :residence_cities,  :path => :cities, :as => :cities 

Changing as: => :cities to :as => :cities

Read more about this syntax here: https://stackoverflow.com/a/44005425/4797110

Mayur Patel
  • 759
  • 7
  • 16