Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root route should be configurable #1656

Closed
jagthedrummer opened this issue Aug 19, 2024 · 0 comments · Fixed by bullet-train-co/bullet_train-core#1013
Closed

Root route should be configurable #1656

jagthedrummer opened this issue Aug 19, 2024 · 0 comments · Fixed by bullet-train-co/bullet_train-core#1013

Comments

@jagthedrummer
Copy link
Contributor

Currently we've hard coded the root routes, but it would be nice to be able to configure them somehow.

https://github.com/bullet-train-co/bullet_train-core/blob/346d5b1adfaaec4046eece13a73b812e3645ada0/bullet_train/config/routes.rb#L7

https://github.com/bullet-train-co/bullet_train-core/blob/346d5b1adfaaec4046eece13a73b812e3645ada0/bullet_train/config/routes.rb#L19

I tried doing this:

root to: "my_new_root_controller#index"

But it throws an error when it reaches the root route from the bullet_train gem.

Invalid route name, already in use: 'root'
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created

CleanShot 2024-08-19 at 11 39 15

jagthedrummer added a commit to bullet-train-co/bullet_train-core that referenced this issue Jan 29, 2025
Previously if you tried to declare a public root route (without a unique
`as:` reference) you'd get an `ArgumentError` saying:

```
Invalid route name, already in use: 'root'
```

Similary if you tried to declare an account scoped dashboard route (with
an `as: 'dashboard'` reference) you'd get an `ArgumentError` saying:

```
Invalid route name, already in use: 'account_dashboard'
```

Both of these errors were happening when we tried to draw default routes
after the application had already declared them.

Now we resuce the `ArgumentError` and check the message to see if it's a
complaint about a duplicate route. If so, we do nothing and let the app
use the route defined in the primary `config/routes.rb` file.

Fixes bullet-train-co/bullet_train#1656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant