Can't Find a Route with an Underscore or Doesn't Treat It Properly

Can't find a route with an underscore or doesn't treat it properly

Rails inflects _ to be a word separator, so it searches for Api::V34 you can change that behavior by editing config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'V3_4'
end

Moreover, if you want to change Api namespace to API, since it's an acronym, you can do it there as well:

ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'V3_4'
inflect.acronym 'API'
end

More info: http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html

Routing errors when upgrading from rails 3.1 to rails 3.2 due to underscores in module namespaces

Came across same thing once.
There was this bug on their github issue list

https://github.com/rails/rails/issues/5849

Then a pull request

https://github.com/rails/rails/pull/6105

But the discussion did not come to any solution. The common statement was like

Don't like undescores in Modules.

So you'll have to remove your underscores from the Module names

Routes with Dash `-` Instead of Underscore `_` in Ruby on Rails

With Rails 3 and later you can do like this:

resources :user_bundles, :path => '/user-bundles'

Another option is to modify Rails, via an initializer.
I don't recommend this though, since it may break in future versions (edit: doesn't work in Rails 5).

Using :path as shown above is better.

# Using private APIs is not recommended and may break in future Rails versions.
# https://github.com/rails/rails/blob/4-1-stable/actionpack/lib/action_dispatch/routing/mapper.rb#L1012
#
# config/initializers/adjust-route-paths.rb
module ActionDispatch
module Routing
class Mapper
module Resources
class Resource
def path
@path.dasherize
end
end
end
end
end
end

Vue Router works fine in development, but doesn't match routes in production

Finally after completely rebuilding my router piece by piece, I found the issue. I found that the problem was in this global route guard:

router.beforeEach((to, from, next) => {
if (store.getters.isAuthenticated) {
next();
} else if (to.name === LOGIN || to.name === SIGNUP) {
next();
} else {
next({ name: LOGIN });
}
});

Specifically, the isAuthenticated getter was throwing an error (silently), so all of the routes were failing before they could render. I wrapped my isAuthenticated logic in a try-catch that returns false if an error is thrown, and now everything works fine.

I still don't understand why this only affects the production build, but hopefully this experience will be useful to others stuck in the same situation.

Flutter error Could not navigate to initial route

I think the error logs are quite explicit.

Since you used '/' to divide your routes it's interpreted as "sub-routes".
Actually it is trying to go through these routes one after an other:

* /
* /animals
* /animals/cats
* /animals/cats/lolcats

And since /animals/cats isn't define, t is getting an error and then is coming back to initial route : /

If you want to solve this problem rename your routes with underscore like this :
/animals_cats_lolcats
So it won't try to get /animals/cats which doesn't exist



Related Topics



Leave a reply



Submit