2016-02-29 51 views
0

我是初學者導軌開發者。我有這個問題: 我有我的路線資源。 資源導軌改變路線系統

resources :events, only: [:index, :show, :comment] do 
    member do 
     post :comment 
     get :will_go 
    end 
    end 

然後在事件模型我有這個關係 事件belongs_to的城市 和使用friendly_id寶石,我的城市模型 城市的has_many事件

,對於做我自己的路線。現在我有鏈接像事件: http://localhost:3000/events/moscow/concert_of_madonna/49 其中 莫斯科 - 是城市 concert_of_madonna的標題 - 是事件 49的標題段塞事件ID

但是,我們需要做的是這樣的: http://localhost:3000/moscow/events/concert_of_madonna/49 所以我需要切換城市標題和資源。

我知道我可以用路線做,但我沒有成功。

我該怎麼辦?

回答

1

我想你正在尋找的是scope

scope ':city' do 
    resources :events, only: [:index, :show, :comment] do 
    member do 
     post :comment 
     get :will_go 
    end 
    end 
end