Rails path helper for namespace

Viewed 138

I've created a simple Rails application for the sake of debugging which has the following config/routes.rb:

Rails.application.routes.draw do
  namespace :ethan_is_cool do
    scope path: "/:message" do
      get "/go_big", to: "transformations#uppercase"
    end
    get "/profile", to: "profile#index"
    get "/users/:id", to: "users#show"
  end
end

When I run rails routes, I get the following:

               Prefix Verb URI Pattern                              Controller#Action
 ethan_is_cool_go_big GET  /ethan_is_cool/:message/go_big(.:format) ethan_is_cool/transformations#uppercase
ethan_is_cool_profile GET  /ethan_is_cool/profile(.:format)         ethan_is_cool/profile#index
        ethan_is_cool GET  /ethan_is_cool/users/:id(.:format)       ethan_is_cool/users#show

This means that there is an ethan_is_cool_path which refers for some reason to the last route:

irb(main):001:0> Rails.application.routes.url_helpers.ethan_is_cool_path(id: 1)
=> "/ethan_is_cool/users/1"

Is this behavior correct or is it a bug? I might have expected ethan_is_cool_users_path, but not ethan_is_cool_path. ethan_is_cool is the name of a namespace, and it doesn't really make sense for it to have a route.

If this behavior is correct, can you point me to some documentation that explains it? I've read https://guides.rubyonrails.org/routing.html but it mostly focuses on resourceful routes and it isn't especially clear what controls the names of helper methods.

0 Answers
Related