2012-08-13 90 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' 

然后你就可以把某种形式的认证,以管理员命名空间。

希望这可以帮助你的方式。