I'm upgrading from rails 3.1.3 to 3.2.2, but for some reason now url_for always returns /assets if the route doesn't exist.
For example:
url_for({}) #=> "/assets"
url_for({action: 'fake', controller: 'notreal'}) #=> /assets?action=fake&controller=notreal
But I want it to to throw the normal ActionController::RoutingError as it normally does...
I have a custom Breadcrumb component that needs access to the global set of route params in order to render properly (swapping out the param numbers for their respective names). Having the params be relative is really counter-intuitive, especially since the location URL is available globally.
@lazarljubenovic The routing in react-router is hierarchical. Each <Route> evaluates the current location based on it's own props and propagates the result down the tree via context. In the above example, the outer route has no knowledge of the inner route.
It's not your typical error. If it were, you wouldn't have sworn under your breath. Cannot read property 'state' of undefined, no worries. You've seen that one plenty of times. This one was different. It wasn't even that the app crashed, it's deeper than that. You stare at your monitor through your fingers. That's it. That's all you get.
Route for invalid routing should be placed at the last of all routes because routes are called in the order in which they are written. If we will write this route in the starting or in the middle somewhere then all routes which are written after this route will not work and will be redirected to be handled as the invalid route.
Rails does not check for route existence if you build up the route via specifying controller-action. And naturally it shows /assets for {} route.
You should better specify named routes in routes.rb and then use them for url_for. Like:
url_for add_user_path
This ensures you will either succeed (for existent named route) or get an error.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With