2012-01-07 61 views
0

使自定義路線我有一個恩基博客成立,並在www.localhost:3000/admin .`Rails的:如何從資源

中的符號,我猜測,這個管理URL被該代碼的路線確定,但是,額外的安全考慮,我想使登錄,例如,

www.localhost:3000/ilovejesus

Enki::Application.routes.draw do 
    namespace 'admin' do 
    resource :session 

基於什麼耙路線告訴我,我猜它是admin_root去:controller => Admin/Dashboard, :action => 'show'需要改變。

因此,誰能告訴我怎麼可能會改變這個太,例如,本地主機:3000/iloveronpaul

耙路線:

admin_session POST /admin/session(.:format)      {:action=>"create", :controller=>"admin/sessions"} 
    new_admin_session GET /admin/session/new(.:format)     {:action=>"new", :controller=>"admin/sessions"} 
    edit_admin_session GET /admin/session/edit(.:format)     {:action=>"edit", :controller=>"admin/sessions"} 
        GET /admin/session(.:format)      {:action=>"show", :controller=>"admin/sessions"} 
        PUT /admin/session(.:format)      {:action=>"update", :controller=>"admin/sessions"} 
        DELETE /admin/session(.:format)      {:action=>"destroy", :controller=>"admin/sessions"} 
preview_admin_posts POST /admin/posts/preview(.:format)     {:action=>"preview", :controller=>"admin/posts"} 
     admin_posts GET /admin/posts(.:format)       {:action=>"index", :controller=>"admin/posts"} 
        POST /admin/posts(.:format)       {:action=>"create", :controller=>"admin/posts"} 
     new_admin_post GET /admin/posts/new(.:format)      {:action=>"new", :controller=>"admin/posts"} 
    edit_admin_post GET /admin/posts/:id/edit(.:format)     {:action=>"edit", :controller=>"admin/posts"} 
      admin_post GET /admin/posts/:id(.:format)      {:action=>"show", :controller=>"admin/posts"} 
        PUT /admin/posts/:id(.:format)      {:action=>"update", :controller=>"admin/posts"} 
        DELETE /admin/posts/:id(.:format)      {:action=>"destroy", :controller=>"admin/posts"} 
preview_admin_pages POST /admin/pages/preview(.:format)     {:action=>"preview", :controller=>"admin/pages"} 
     admin_pages GET /admin/pages(.:format)       {:action=>"index", :controller=>"admin/pages"} 
        POST /admin/pages(.:format)       {:action=>"create", :controller=>"admin/pages"} 
     new_admin_page GET /admin/pages/new(.:format)      {:action=>"new", :controller=>"admin/pages"} 
    edit_admin_page GET /admin/pages/:id/edit(.:format)     {:action=>"edit", :controller=>"admin/pages"} 
      admin_page GET /admin/pages/:id(.:format)      {:action=>"show", :controller=>"admin/pages"} 
        PUT /admin/pages/:id(.:format)      {:action=>"update", :controller=>"admin/pages"} 
        DELETE /admin/pages/:id(.:format)      {:action=>"destroy", :controller=>"admin/pages"} 
     admin_comments GET /admin/comments(.:format)      {:action=>"index", :controller=>"admin/comments"} 
        POST /admin/comments(.:format)      {:action=>"create", :controller=>"admin/comments"} 
    new_admin_comment GET /admin/comments/new(.:format)     {:action=>"new", :controller=>"admin/comments"} 
    edit_admin_comment GET /admin/comments/:id/edit(.:format)    {:action=>"edit", :controller=>"admin/comments"} 
     admin_comment GET /admin/comments/:id(.:format)     {:action=>"show", :controller=>"admin/comments"} 
        PUT /admin/comments/:id(.:format)     {:action=>"update", :controller=>"admin/comments"} 
        DELETE /admin/comments/:id(.:format)     {:action=>"destroy", :controller=>"admin/comments"} 
undo_admin_undo_item POST /admin/undo_items/:id/undo(.:format)   {:action=>"undo", :controller=>"admin/undo_items"} 
    admin_undo_items GET /admin/undo_items(.:format)      {:action=>"index", :controller=>"admin/undo_items"} 
        POST /admin/undo_items(.:format)      {:action=>"create", :controller=>"admin/undo_items"} 
new_admin_undo_item GET /admin/undo_items/new(.:format)     {:action=>"new", :controller=>"admin/undo_items"} 
edit_admin_undo_item GET /admin/undo_items/:id/edit(.:format)   {:action=>"edit", :controller=>"admin/undo_items"} 
    admin_undo_item GET /admin/undo_items/:id(.:format)     {:action=>"show", :controller=>"admin/undo_items"} 
        PUT /admin/undo_items/:id(.:format)     {:action=>"update", :controller=>"admin/undo_items"} 
        DELETE /admin/undo_items/:id(.:format)     {:action=>"destroy", :controller=>"admin/undo_items"} 
     admin_health  /admin/health(/:action)(.:format)    {:action=>"index", :controller=>"admin/health"} 
      admin_root  /admin(.:format)        {:controller=>"admin/dashboard", :action=>"show"} 
      archives GET /archives(.:format)        {:action=>"index", :controller=>"archives"} 
       page GET /pages/:id(.:format)       {:action=>"show", :controller=>"pages"} 
        GET /:year/:month/:day/:slug/comments(.:format)  {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"index"} 
        POST /:year/:month/:day/:slug/comments(.:format)  {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"create"} 
        GET /:year/:month/:day/:slug/comments/new(.:format) {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"new"} 
        GET /:year/:month/:day/:slug(.:format)    {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"posts", :action=>"show"} 
    formatted_posts GET /posts.:format         {:controller=>"posts", :action=>"index"} 
       posts GET /(:tag)(.:format)        {:controller=>"posts", :action=>"index"} 
       root  /(.:format)          {:controller=>"posts", :action=>"index"} 
+0

你可以發佈你的整個routes.rb文件嗎? – nmott 2012-01-08 12:34:20

回答

1

添加:路徑選項,您namespace

Enki::Application.routes.draw do 
    scope :module => 'admin' do 
    resource :session, :path_names => { :new => "liverandonions", 
             :show => "ilovejesus, 
             :edit => "iloveronpaul" } 

我不確定,但path_names選項可能必須包裝在數組中。

即。

resource :session, :path_names => { [:new => "liverandonions", 
             :show => "ilovejesus, 
             :edit => "iloveronpaul"] } 

讓我知道哪一個可以工作。

+0

謝謝,但是那個路徑會影響localhost:3000/admin還是會影響命名空間中的每個'admin'路徑? – Leahcim 2012-01-07 22:07:03

+0

名稱空間中的每條路徑。這裏有一個指向[命名空間路由文檔]的鏈接(http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Scoping.html#method-i-namespace) – Azolo 2012-01-07 22:53:07

+0

好的,但我認爲也有一種方法就是改變那一個網址,但我無法弄清楚。你偶然知道嗎? – Leahcim 2012-01-07 23:40:52