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

Convert dashes in scope/slice URL fragments to underscores in URL helpers #280

Open
svoop opened this issue Feb 13, 2025 · 0 comments · May be fixed by #281
Open

Convert dashes in scope/slice URL fragments to underscores in URL helpers #280

svoop opened this issue Feb 13, 2025 · 0 comments · May be fixed by #281

Comments

@svoop
Copy link

svoop commented Feb 13, 2025

By convention (better SEO etc), dashes are preferred over underscores in URLs, but this results in ugly helpers. Here's an example:

# config/routes.rb

module Dashy
  class Routes < Hanami::Routes

    get "foo", to: "action.foo", as: :foo

    scope "myscope" do
      get "foo", to: "action.foo", as: :foo
    end

    scope "my-scope" do
      get "foo", to: "action.foo", as: :foo
    end

    slice :myslice, at: "/myslice" do
      get "foo", to: "action.foo", as: :foo
    end

    slice :my_slice, at: "/my-slice" do
      get "foo", to: "action.foo", as: :foo
    end
  end
end

The following routes and URL helpers are created:

GET  /foo            action.foo   as :foo
GET  /myscope/foo    action.foo   as :myscope_foo
GET  /my-scope/foo   action.foo   as :"my-scope_foo"  <--
GET  /myslice/foo    action.foo   as :myslice_foo
GET  /my-slice/foo   action.foo   as :"my-slice_foo"  <--

For the URL helpers, the dashes should be converted to underscores like so:

GET  /foo            action.foo   as :foo
GET  /myscope/foo    action.foo   as :myscope_foo
GET  /my-scope/foo   action.foo   as :my_scope_foo   <--
GET  /myslice/foo    action.foo   as :myslice_foo
GET  /my-slice/foo   action.foo   as :my_slice_foo   <--

Discussion: https://discourse.hanamirb.org/t/route-scopes-with-dashes/1120

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