Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Routes not doing what I would like them to do. #618
I have a route like this in one of my controllers
get :reindex do
When I do a padrino rake routes I see
(:tracks, :reindex) GET /tracks/re
Why is the router just chopping off the word index in any context?
furthermore could you actually explain why index seems to be the only one of the methods that has a special meaning in the context of the router?
delete :destroy do ...
automatically map to something like
(:tracks, :destroy) DELETE /tracks/:id
The whole thing just seems very inconsistent to me, and I have always wondered why it worked this way.
@philly-mac Yeah I totally agree this needs to be fixed and perhaps rethought about. Here is the exact method/lines: https://github.com/padrino/padrino-framework/blob/master/padrino-core/lib/padrino-core/application/routing.rb#L588. Right now we are doing a regex that is clearly not working. We should add a failing test for an action called reindex.
I can see the case for "stripping" out any of the reserved actions from the path as you suggest. "destroy" action becomes: DELETE /resource/id, etc to stick with restful conventions. Perhaps the key is to support this with a separate plugin, I am not entirely sure. Perhaps we can brainstorm a "better" way for routing to work which can be enabled that makes all destroy,update,show,create,index all reserved words? @DAddYE what do you think about this idea.
@nesquena A plugin would be a good solution I think, something that you could just require to get the restful type routes. I went back to actually look at the way sinatra was doing its routes, and I like them because they are simple and consistent, and sometimes I would just like to be able to use routes as defined by sinatra.
So I think a plugin should add that when any of the 7 methods are used in their proper context then they become the restful route.
delete :destroy do... #=> DELETE /resource/:id
I think it only makes sense to reserve the rest methods for the http methods that they apply to, and not just globally.
Also the rails guides has a perfect table of all methods and what they should map to http://guides.rubyonrails.org/routing.html
What do you think?
You can use sinatra routing directly as well passing a string directly. The symbol notation is an optional addition. So you can still do:
get "/foo/bar" do end
in Padrino. I do think a plugin or a flag to support the restful paths by default by stripping the various keywords when used in the right context is not a bad idea at all. I can see using it in various places throughout APIs.