2013-02-28 70 views
-1

Ruby on rails具有輕鬆創建資源收集路線的功能。但是在控制器中,我們如何檢測該集合路由是否與當前請求匹配。如何檢測是否使用收集路徑進行請求?

resource :posts, :only => [:index, :show] do 
    collection do 
    get :archived, :action => :index 
    end 
end 

因此,在帖子#索引動作,我該如何檢查索引動作的哪條路線匹配? (索引或存檔)應該有一個乾淨的方式來做到這一點。

+0

你是問時是否有在一個單一的動作指向多條路線,你是否可以在運行時哪一個決定是匹配的? – 2013-02-28 12:26:39

+0

我想在運行時確定哪一個匹配了 – 2013-02-28 12:27:03

+0

真的嗎?對於你沒有問自己的問題,你會拋棄我的完全不相關的答案,因爲你對我感到不滿。 – deefour 2013-02-28 12:45:44

回答

0

使用

耙路線

,看看在你的應用程序中的所有路由。輸出將是這樣的。

welcome_index GET /welcome/index(.:format) welcome#index 
     users GET /users(.:format)   users#index 
       POST /users(.:format)   users#create 
    new_user GET /users/new(.:format)  users#new 
    edit_user GET /users/:id/edit(.:format) users#edit 
     user GET /users/:id(.:format)  users#show 
       PUT /users/:id(.:format)  users#update 
       DELETE /users/:id(.:format)  users#destroy 
     root  /      welcome#index 

你應該通過這個.. Learn routing better from here

+0

這不是我所問的。 – 2013-02-28 17:41:56

+0

爲什麼你看不到你的服務器日誌,......當你請求一個頁面時,它會像「開始get/some/something」。 – 2013-03-01 06:28:08

相關問題