arvindvyas / Country-State-Select

It will fetch the countries and according to that fetch the state of that countries, currently it is for countries listing
MIT License
69 stars 78 forks source link

Be careful with catch-all routing in your application #42

Closed aldefouw closed 5 years ago

aldefouw commented 8 years ago

On one of the applications that I used this gem in, I had a route matcher at the end of the routes.rb file.

Something like this:

match '*unmatched_route', to: 'application#not_found', :via => :all

All was fine and dandy, but suddenly the POST routes for this gem (which are crucial to the gem) stopped working.

You know why?

Because of the order that the routes were configured in the manifest, #find_states and #find_cities was no longer routing to the CscsController.

They were now routing to the ApplicationController#not_found.

@arvindvyas - See my post below for how I fixed this ....

aldefouw commented 8 years ago

@arvindvyas

https://github.com/aldefouw/Country-State-Select/commit/a349d4ff1f0e149f7982f371fc593e88cf4fb840

Adding the above code to the routes.rb file would allow the routes to be mountable. I created a version on my development branch so that I can use this for the application I am using.

You'd have to be careful about releasing this one because it would break unless people added this line:

mount CountryStateSelect::Rails::Engine, at: "/"

(The above line is added to routes.rb in your app that users the gem.)

arvindvyas commented 8 years ago

I will look this in this weekend

aldefouw commented 8 years ago

Thanks @arvindvyas . Nice work on the gem, too. The newest version looks really good.