1

지금까지 내 routes.rb 파일은 다음과 같이 보입니다 수행자원의 내부 경로를 레일 : ㅋ ㅋ

resources :games do 
    resources :planets do 
    member do 
     get 'index' as: :play_game 
    end 
    end 
end 

이를 생성

play_game_game_planet GET /games/:game_id/planets/:id/index(.:format) planets#index 
     game_planets GET /games/:game_id/planets(.:format)   planets#index 
         POST /games/:game_id/planets(.:format)   planets#create 
    new_game_planet GET /games/:game_id/planets/new(.:format)  planets#new 
    edit_game_planet GET /games/:game_id/planets/:id/edit(.:format) planets#edit 
     game_planet GET /games/:game_id/planets/:id(.:format)  planets#show 
         PATCH /games/:game_id/planets/:id(.:format)  planets#update 
         PUT /games/:game_id/planets/:id(.:format)  planets#update 
         DELETE /games/:game_id/planets/:id(.:format)  planets#destroy 

하지만 경로 I (나는 레이크 경로를 검사 할 때) 원하는 당신은 이미 game_planets /games/:game_id/planets(.:format) planets#index 경로가 위의 정의

play_game GET /games/:game_id/planets(.:format)   planets#index 

답변

1

(두 번째 줄과 유사)합니다 - NA med 경로는 game_planets입니다. 그래서 네가 원하는 경로가 명명 된 경로와 다른 이름이라고 가정한다.

그 다음이 할 수있는 당신이 후에이고 당신은 특별한 언급 할 수없는 것을 (경로 구조라는 표준이 아닌 이유는이보고 즉 다른 레일 개발자들이 궁금해 것)의 경우 :

resources :games do 
    resources :planets 
end 

get 'games/:game_id/planets', 'planets#index', as: 'play_game' 

이것은 본질적으로 특별한 이름의 라우트로 중복 라우트를 작성합니다.

  1. 색인 작업이 복수라는 이름의 경로를 사용해야합니다
  2. 그것은 표준이 아니다 (그래서 적어도 as: 'play_games' 사용) :하지만 때문에 반대 권하고 싶습니다. 명명 된 경로 play_game은 내게 Game 컨트롤러가 중첩 된 PlayController이고 이것이 play 개체가 전달되어야하는 show 동작이 될 것이라고 생각하게 만듭니다.
+0

정확히 내가 리소스 블록 내부에서 이름을 지정하면 상황이 추가되지만 외부에서 제대로 작동하면됩니다. –

관련 문제