2015-04-07 56 views

回答

1

如果你想要的资源games充当根路径,你可以设置它的路径“/”在routes.rb中

resources :games, path: '/' 

如果你只希望它为show动作(如我想你做的),使用方法:

resources :games, path: '/', only: [:show] 
resources :games, except: [:show] 

(这会给http://localhost:3000/first-game

或第三这可能是最明智的,以避免冲突的途径,呼吁使用单数“游戏”路径show行动:

resources :games, path: 'game', only: [:show] 
resources :games, except: [:show] 

(这会给http://localhost:3000/game/first-game

+0

嗨mgrim感谢,最后一个选项的作品,但不破坏行动。 – ajin6747

+0

它不?有趣。 (我假设你在两行中都有''':show,:destroy]''')什么是'''$ rake routes'''输出? – mgrim

+0

添加后:销毁它,但编辑停止。 $ rake路由输出: - 前缀动词URI模式控制器#动作 edit_game GET /game/:id/edit(.:format)games#edit GET /game/:id(.:format)games#show DELETE /游戏/:id(。:format)games#destroy 游戏GET /games(.:format)games#index POST /games(.:format)games#create new_game GET /games/new(.:format)games #new PATCH /games/:id(.:format)games#update PUT /games/:id(.:format)games#update – ajin6747

0

你可以为你的行动像这样创建一个自定义路线:

get '/games/first-game' => 'Games#first_game' 
0

你可以做:

resources :games 
    member do 
    get 'first-game', to: 'games#first_game', as: :first_game 
    end 
end 

Naming Routes指南。