Resources routes include "/elixir/appname"
Closed this issue · 3 comments
I have created Weber application named trash - https://github.com/darkofabijan/trash (It's not a joke I really want to make app with that name. It's for some public activity for reporting broken trash bins in my town).
I have defined resources route:
route on("GET", "/", :Trash.Main, :index)
|> resources(:Trash.Bins)
From app: https://github.com/darkofabijan/trash/blob/master/lib/route.ex#L7
Expected behavior would be that it generates following routes:
GET /trash/bins Trash.Bins#index
GET /trash/bins/new Trash.Bins#new
POST /trash/bins Trash.Bins#create
GET /trash/bins/:id Trash.Bins#show
GET /trash/bins/:id/edit Trash.Bins#edit
PUT /trash/bins/:id Trash.Bins#update
DELETE /trash/bins/:id Trash.Bins#index
Instead it generates:
GET /elixir/trash/bins Trash.Bins#index
GET /elixir/trash/bins/new Trash.Bins#new
POST /elixir//trash/bins Trash.Bins#create
GET /elixir//trash/bins/:id Trash.Bins#show
GET /elixir/trash/bins/:id/edit Trash.Bins#edit
PUT /elixir/trash/bins/:id Trash.Bins#update
DELETE /elixir/trash/bins/:id Trash.Bins#index
It could be fixed by changing API to resources(:bins)
. And it would be convention map to Trash.Bins controller.
Next iteration could be to allow mapping to custom controller:
resources(:bins, [controller: Trash.CrazyBins])
and specifying just certain actions would be also interesting. e.g.
resources(:bins, [only: {:index, :show}])
resources(:plastic_bins, [except: {:destroy}])
I think that could manage to implement that, but I am not sure how to write integration tests that would show the bug. Current test for router doesn't catch that issue - https://github.com/0xAX/weber/blob/master/test/route_test.exs.
In test weber app bug can be seen from these tests - https://github.com/darkofabijan/trash/blob/master/test/response_test.exs.
It seems kind of tricky to write integration test for framework without generating some test application on the fly. Any guidance would be much appreciated. :)
P.S.
I really like how things work in weber so far. I use Rails for five years now and I have a feeling that it could be nicely accepted in Ruby/Rails community.
Hello @darkofabijan,
I removed elixir
part from url in route.
About mapping to the new controller/actions, can you create separate issue please, We will disqus it after 0.0.5 release, i'll make it today.
Cool, thanks. I will move it.