2014-09-25 52 views
0

我需要一點關於RESTful路由的幫助。基本上,即時通訊嘗試重新創建http://medium.com以幫助提高我的導軌技能。Rails多用戶博客路由

我通過Devise完成註冊。

我卡在實際的博客路由。我想要的路線是這樣的:domain.com/username/post-title。我不確定是否有可能使這種應用程序遵循寧靜的模式。

我該怎麼做?

我的想法做這樣的:

scope module: :username do 
    resources :posts 
end 

但是當我耙路線,我只是得到一些奇怪:

posts GET /posts(.:format)     username/posts#index 
        POST /posts(.:format)     username/posts#create 
    new_post GET /posts/new(.:format)    username/posts#new 
      edit_post GET /posts/:id/edit(.:format)   username/posts#edit 
       post GET /posts/:id(.:format)    username/posts#show 
        PATCH /posts/:id(.:format)    username/posts#update 
        PUT /posts/:id(.:format)    username/posts#update 
        DELETE /posts/:id(.:format)    username/posts#destroy 
       root GET /        home#index 

這些路由的網址仍然停留/posts和一些原因是沒有:username/posts

我真的不知道如何評價這一點。

謝謝! :)

+0

你應該多看一些關於這裏的路由模塊名稱 - http://guides.rubyonrails.org/routing.html你也必須定義 – 2014-09-25 05:35:28

+0

的關係在你的模型 – 2014-09-25 05:36:50

+0

閱讀更多關於它在這裏 - http://stackoverflow.com/questions/11888587/show-certain-users-blog-posts-in-rails – 2014-09-25 05:38:36

回答

1

那是因爲你正在使用'範圍'。嘗試使用「命名空間」來代替,如果你在你的網址要

namespace :username do 
    resources :posts 
end