2012-08-13 85 views
1

目前我正在研究RoR中的博客引擎,並遇到與路由有關的severa問題。 的routes.rb看起來是這樣的:重寫Rails路線

match '/admin', :to => 'posts#new' 
match '/get/:id', :to => 'posts#get' 
match '/new', :to => 'posts#new' 
delete '/:id', :to => 'posts#destroy' 
post '/edit/:id', :to => 'posts#update' 
put '/edit/:id', :to => 'posts#update' 
get '/edit/:id', :to => 'posts#new', :as => 'post' 
get '/:slug', :to => 'posts#show', :as => 'post' 
root :to => 'posts#index' 

,我想改造它是這樣的:

resources :admin do 
    resources :posts 
end 

任何幫助將是非常讚賞。

回答

1

需要更多信息。你想在管理資源中放置什麼?只發布,還是編輯?

但是一些提示開始: - 你必須拆分你的文章控制器。在名爲admin的控制器(資源名稱)中創建一個子文件夾。將管理功能移到此控制器,並將公共職位功能(索引和顯示)保留在正常的posts_controller中。 - 對視圖執行相同操作。

而且,我懷疑你想要的路線是:

namespace :admin 
    resources :posts 
end 

get '/:id', :to => 'posts#show' 

root :to => 'posts#index' 

然後你就可以把某種形式的認證,以管理員命名空間。

希望這可以幫助你的方式。