2016-08-08 5 views
0

내 레일 애플리케이션에 추종자를 추가하려고합니다. 내 서버 시작 rails s을 실행할 때 다음과 같은 오류를보고하고있다 :잘못된 경로 이름 (이미 사용 중) : 'user'

Invalid route name, already in use: 'user' (ArgumentError) 
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created 

경로를

Rails.application.routes.draw do 
    devise_for :users 
    resources :users do 
    member do 
     get :following, :followers 
    end 
    end 
    resources :relationships, only: [:create, :destroy] 
    resources :posts do 
    member do 
     post '/like' => 'posts#like' 
    end 
    end 
    get ':username' => 'users#show', as: 'user' 

    root 'home#index' 

    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 
end 

내가 추가 한 알고 도움이 될 수

:

resources :users do 
    member do 
     get :following, :followers 
    end 
    end 
    resources :relationships, only: [:create, :destroy] 

위의 내용을 추가하기 전에 레일 응용 프로그램이 작동했습니다.


나는 아마도 이것이 간단한 수정 일 것이라고 확신하지만 레일을 처음 사용합니다. 저는 한 시간 이상 길 찾기와 온라인 검색을 해왔으며 문제를 이해하고 해결하려고 노력했습니다. 더 많은 지식을 가진 사람이 나를 올바른 방향으로 안내 할 수 있기를 바랍니다.

답변

3

아직 이미 정의 된 경로와 충돌이 같은 경로를 사용하지 devise_for users 만든 몇 가지 경로가을 고안 사용하고 있기 때문에. 대신에 사용하는 as: :useras::user_profile

같은 다른 관련 이름을 넣어은 당신의 경우

+0

감사합니다 : 당신이 중 하나

devise_for :users, :path_prefix => 'auth' resources :users 

참조, 특정 접두사처럼 아래 을 고안를 넣을 수 있습니다! 그게 내 문제를 해결해 줬어. 나는 심지어 그것을 알아 차리지 못했다. – GVS

+0

진심으로 환영합니다. –

관련 문제