开发者

Root-level routing with Ruby on Rails?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜