开发者

How do I get rid of the controller name in a resourceful route?

Using 2.3. Is there a way 开发者_运维百科to get rid of a controller name in my route?

For example, I'd like www.example.com/:username to go to that user's profile (similar to how facebook does it).

I could just do

map.user '/:id'
map.feed '/:id/feed'
map.friends '/:id/friends'
...

but it's not resourceful. Is there a better way?

map.resources :users, :as=>"" do |user| ...

maps //:id/feed and //:id/friends but not without the double slash.


If I understand correctly then you are looking for the :member symbol. I know it works in rails 3, not 100% sure about rails 2.

map.connect ':id', :controller => :users, :action => :show do
  :member => { :feed => :get }
  :member => { :friends => :get }
end

Here is a link to the documentation if that code block is not correct.

http://guides.rubyonrails.org/v2.3.11/routing.html#adding-more-restful-actions


There appears to be an answer, but it requires I monkey patch the ActionController::Resources::Resource class.

...

I just used non-resourceful routes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜