开发者

Root-level routing with Ruby on Rails?

开发者 https://www.devze.com 2023-03-04 14:24 出处:网络
How do I efficiently enable root-level routing with Ruby on Rails? For example, instead of开发者_C百科 having:

How do I efficiently enable root-level routing with Ruby on Rails?

For example, instead of开发者_C百科 having:

/questions/a-question-here

I want:

/a-question-here

What technology would I use, and how would I configure the routing to enable this?

EDIT: I also have other models such as videos and users, so I'd like the routing to match other controllers as well. For example, how do I get /username to go to some action in the Users controller and /some-video-title to go to some action in the Videos controller?

Thanks for all your help, people.


Rails has a very configurable routing layer built in. Good documentation here:

http://guides.rubyonrails.org/routing.html

Your route could end up looking something like this:

match ":id" => "questions#show"

Depending on where you put that, it could override a lot of other routes, so be aware of that.

0

精彩评论

暂无评论...
验证码 换一张
取 消