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

Routes not doing what I would like them to do. #618

Closed
philly-mac opened this issue Aug 5, 2011 · 13 comments
Closed

Routes not doing what I would like them to do. #618

philly-mac opened this issue Aug 5, 2011 · 13 comments
Assignees
Milestone

Comments

@philly-mac
Copy link

Hi,

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?

Why doesn't

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.

Thanks

@ghost ghost assigned joshbuddy Aug 5, 2011
@DAddYE
Copy link
Member

DAddYE commented Aug 5, 2011

For the first question index is a reserved word,

@joshbuddy?

@philly-mac
Copy link
Author

I understand that index may be reserved, but is reindex?
That would be like saying you couldn't use "definitely" as a ruby method because it contains the word def.

@DAddYE
Copy link
Member

DAddYE commented Aug 5, 2011

You are right, but we need to parse better to replace index with /, Im sure @joshbuddy will patch it... soon. :D

@philly-mac
Copy link
Author

Cool.

Which part of the framework deals with this? I might take a look at it myself also

@nesquena
Copy link
Member

nesquena commented Aug 5, 2011

@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.

@philly-mac
Copy link
Author

@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.
i.e.

delete :destroy do... #=> DELETE /resource/:id
but
get :destroy do... #=> GET /resource/destroy

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?

@nesquena
Copy link
Member

nesquena commented Aug 5, 2011

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.

@philly-mac
Copy link
Author

Ahhh okay, but with the string notation you do not get any routes displayed with the padrino rake routes command. It was kind of misleading.

@philly-mac
Copy link
Author

Also I don't know if you actually mention in the docs anywhere that the symbol notation is Padrino and string notation will give you sinatra routes, but you should make that clear somewhere as it is actually very useful to know.

@philly-mac
Copy link
Author

Strike my last comment, I just looked through the guides again, and it does mention the distinction of the symbols

@nesquena
Copy link
Member

nesquena commented Aug 9, 2011

Added a failing test above, i.e reindex action

@joshbuddy
Copy link
Contributor

Yeah, I'm working on this.

@joshbuddy
Copy link
Contributor

Fixed in 790f349

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

No branches or pull requests

4 participants