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

Order of routes affects pretty URLs #43

Closed
jaimeiniesta opened this issue Sep 21, 2014 · 9 comments
Closed

Order of routes affects pretty URLs #43

jaimeiniesta opened this issue Sep 21, 2014 · 9 comments

Comments

@jaimeiniesta
Copy link

I've noticed that if you move the main "/" route to the top of the routes file, for example on https://github.com/voltrb/todos3/blob/master/app/main/config/routes.rb leaving it like this,

# The main route
get '/'

get "/todos/{_index}", _action: 'todos'
get "/todos", _action: 'todos'
get "/meal_cost", _action: 'meal_cost'
get "/about", _action: 'about'
get "/collections/{_route}", _action: 'collections'
get "/collections", _action: 'collections'

get "/blog/{_id}/edit", _controller: 'blog', _action: 'edit'
get "/blog/{_id}", _controller: 'blog', _action: 'show'
get "/blog", _controller: 'blog', _action: 'index'
get "/blog/new", _controller: 'blog', _action: 'new'

it affects the URLs so, although the app still works, you get ugly URLs like:

http://localhost:3000/?controller=blog&action=index#

instead of

http://localhost:3000/blog
@dfyx
Copy link
Contributor

dfyx commented Sep 21, 2014

I think this is by design. Rails does basically the same.

@jaimeiniesta
Copy link
Author

I don't think so, I understand that by design, the order of the routes is taken into account in the sense that the first match will be used (like Rails), but this is not the case here.

@ryanstout
Copy link
Member

@jaimeiniesta So this API might need a little more thought to make it intuitive. At the moment its by design, but your right, its not the most intuitive. Right now it matches top to bottom when going from params to a url. (and vice versa) get '/' matches anything, so it should be at the bottom.

@ryanstout
Copy link
Member

I'll leave this one open if anyone wants to discuss their thoughts on the routes. One of my goals with Volt is to have a simple routing system. Not needing to handle different http verbs allows us to simplify things. (Expect extra methods for building REST API's for the backend) I think the idea of routes just mapping params to urls and vice versa could make it easy to learn, but powerful enough to use day to day.

@jaimeiniesta
Copy link
Author

Thanks for the explanation, in my opinion the best place for the root path is at the bottom, but I was surprised by this behavior.

Volt does not need to behave like Rails, but in Rails, you can have the root route on the top of the routes file and everything will still work as if it was at the bottom.

What I don't get is, why is it that get '/' matches anything? In my opinion it should not match anything except exactly / , I don't see any wildcard or optional parameter there.

I must surely be missing something about how routes are matched in Volt, but I can't find it in the docs.

@ryanstout
Copy link
Member

So front-end routing is a different thing than backend routing because you need to go from both url to params and params to url. So you can think of everything after the url string as constraints for matching.

get '/' might be better written as get '/', {}

Something like ```get '/about', {_controller: 'about'}, only matches when the params._controller == 'about'

get '/' matches any params. Maybe I should just make a root helper that just inserts its-self last.

Let me know if that makes since. Its simple, but maybe not intuitive enough. At this point all of these api's are open to change :-)

@jaimeiniesta
Copy link
Author

Ah, alright, thanks a lot for your explanation!

get '/' might be better written as get '/', {}

That was the point that I was missing :)

@ryanstout
Copy link
Member

Cool, thats a good idea. I'll add that.

On Sun, Sep 21, 2014 at 4:39 PM, Jaime Iniesta notifications@github.com
wrote:

Ah, alright, thanks a lot for your explanation!

get '/' might be better written as get '/', {}

That was the point that I was missing :)


Reply to this email directly or view it on GitHub
#43 (comment).

@ryanstout
Copy link
Member

I added some more stuff to the readme and generated routes.rb files. Hopefully that helps newcomers.

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

3 participants