2015-04-03 45 views
0

之前所有,這不是一個最佳實踐的問題,我知道你不喜歡它在SO。不像之前閱讀我的問題!RailsBestPractices - 過度使用路由自定義

我正在使用gem rails_best_practices來檢測我的項目中的一些錯誤操作。最近,我有幾個「過度使用路由定製」(http://rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/)。

我的路線是這樣的:

resources :projects do 
    collection do 
    get :featured 
    get :computed 
    get :static 
    get :blocked 
    end 

鏈接到論文的行動路線只是一個特定的index一國範圍內,像這樣:

def featured 
    @projects = Project.featured.paginate(...) 
end 

我用論文路由具有美麗URL像/projects/featured而不是/projects/?state=featured

我的問題是如何改變目前的路線有與相同的行爲美女的網址?

回答

0

故事之前添加此資源

get '/projects/:state', to: 'projects#index', constraints: { state: /featured|computed|static|blocked/ } 

或者內部:

collection do 
    get '/projects/:state', to: 'projects#index', constraints: { state: /featured|computed|static|blocked/ } 
end