2010-11-22 12 views
1

adminスコープの下にのような新しい物理ディレクトリを作成することなく(namespaceが必要)ルートグループを生成する方法はありますか。相当のスコープ?

私はRailsの3ルートマッパーのscope方法があることを知って、これは私がやりたいように見えますが、どうやらそれはRailsの2.3.x以降では存在しません。私の目標は持っていることです

このようなルート:"/admin/products""app/controllers/products_controller"app/controllers/admin/products_controller"にマップする。

これをRails 2.3.xで実行する方法はありますか?

答えて

4

確かに、あなたが欲しいものを得るために:name_prefix:path_prefixを使用する必要があります。

ActionController::Routing::Routes.draw do |map| 
    map.with_options :name_prefix => 'admin_', :path_prefix => 'admin' do |admin| 
    admin.resources :products 
    end 
end 

はルートが得られます:

admin_products GET /admin/products(.:format)   {:controller=>"products", :action=>"index"} 
        POST /admin/products(.:format)   {:controller=>"products", :action=>"create"} 
new_admin_product GET /admin/products/new(.:format)  {:controller=>"products", :action=>"new"} 
edit_admin_product GET /admin/products/:id/edit(.:format) {:controller=>"products", :action=>"edit"} 
    admin_product GET /admin/products/:id(.:format)  {:controller=>"products", :action=>"show"} 
        PUT /admin/products/:id(.:format)  {:controller=>"products", :action=>"update"} 
        DELETE /admin/products/:id(.:format)  {:controller=>"products", :action=>"destroy"} 
2

十分に文書ではないように見えます、 namespaceは、実際にはwith_optionsの非常に単純なラッパーです。私は、コードを読んでから、この通過つもり

map.with_options :path_prefix => 'admin/' do |admin| 
    admin.connect ':controller/:action' 
end 

:それは私はあなただけ最初、そうしたいと考えていたの:path_prefix:name_prefix、および:namespaceオプションを設定します。 :name_prefixは名前付きルートに接頭辞を付けるために使用され、:namespaceは実際にサブディレクトリを見るのに使用されているようです。