cli icon indicating copy to clipboard operation
cli copied to clipboard

Action generator appends routes even if exists

Open Lucas-Barret opened this issue 1 year ago • 3 comments

When you execute bundle exec hanami generate action books.index several times. You end up with the same routes in routes.rb Example :

$ bundle exec hanami generate action books.index
$ bundle exec hanami generate action books.index

## config/routes.rb

module Bookshelf
  class Routes < Hanami::Routes
    get "/books", to: "books.index"
    get "/books", to: "books.index"
  end
end

We should have the root only one time what do you think ?

Lucas-Barret avatar May 12 '24 17:05 Lucas-Barret

After some investigation it seems it comes from this piece of code : Should we check if the routes is already in the file ?

            fs.inject_line_at_class_bottom(
              fs.join("config", "routes.rb"),
              "class Routes",
              route(controller, action, url, http)
            )

Lucas-Barret avatar May 13 '24 08:05 Lucas-Barret

Yes, I believe so, duplicates have no sense.

swilgosz avatar Oct 11 '24 18:10 swilgosz

Yes, I would love help with a fix for this!

timriley avatar Oct 13 '24 06:10 timriley