2013-02-21 3 views
0

사용자 및 사용자 프로필이있는 프로젝트에서 작업하고 있습니다. 사용자 인증 목적으로 devise gem을 사용하고 있습니다. 설명되지 않는 동작을 초래하는 컨트롤러에서 작업 경로를 변경했습니다.레일에 테이블에 삽입 할 때 속성 값이 변경되는 경우

Test::Application.routes.draw do 
    match '/:username' => 'profile#show' , :as => :username 


    get "profile/update" 

    get "static_pages/index" 

    devise_for :users 

서버 로그는 다음을 보여줍니다.

Started POST "/users" for 127.0.0.1 at 2013-02-22 03:07:48 +0530 
Processing by ProfileController#show as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"Tr90BvI6sztk7gxlPm6KF3td3xIe91SpCZDGsIniv60=", "user"=>{"username"=>"example", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up", "username"=>"users"} 
    Rendered profile/show.html.erb within layouts/application (0.1ms) 
Completed 200 OK in 12ms (Views: 11.5ms | ActiveRecord: 0.0ms) 

데이터는 데이터베이스에 삽입되지 않고 사용자 이름 매개 변수가 변경지고, 나는

match '/:username' => 'profile#show' , :as => :username 

즉 기본 경로로 경로를 변경하면

get "profile/show" 
로 변경

모든 것이 정상으로 돌아 왔습니다. 데이터가 삽입되고 모든 것이 잘 작동합니다. 왜 사용자가 등록 할 때 프로필 컨트롤러의 동작이 호출되는지 이해할 수 없습니다. rake routes는 다음과 같은 출력을 사전에

   username  /:username(.:format)   profile#show 
      profile_update GET /profile/update(.:format)  profile#update 
     static_pages_index GET /static_pages/index(.:format) static_pages#index 
     new_user_session GET /users/sign_in(.:format)  devise/sessions#new 
      user_session POST /users/sign_in(.:format)  devise/sessions#create 
    destroy_user_session DELETE /users/sign_out(.:format)  devise/sessions#destroy 
      user_password POST /users/password(.:format)  devise/passwords#create 
     new_user_password GET /users/password/new(.:format) devise/passwords#new 
     edit_user_password GET /users/password/edit(.:format) devise/passwords#edit 
         PUT /users/password(.:format)  devise/passwords#update 
cancel_user_registration GET /users/cancel(.:format)  devise/registrations#cancel 
     user_registration POST /users(.:format)    devise/registrations#create 
    new_user_registration GET /users/sign_up(.:format)  devise/registrations#new 
    edit_user_registration GET /users/edit(.:format)   devise/registrations#edit 
         PUT /users(.:format)    devise/registrations#update 
         DELETE /users(.:format)    devise/registrations#destroy 
        root  /       static_pages#inde 

감사를 제공합니다.

답변

0

경로가 정의 된 순서대로 일치합니다. /:username은 경로 파일의 맨 위에 정의되어 있고 특이성이 낮기 때문에 나중에 정의 된 경로를 마스킹하는 것으로 보입니다. 그 경로를 파일의 맨 아래로 옮기거나 정규 표현식과 같은 제약 조건을 적용하여 덜 욕심스럽게 만들 것을 제안합니다.

+0

그게 문제를 해결했습니다. 고맙습니다.하지만 다른 컨트롤러와 다른 액션이 지정된 액션보다 어떻게 호출되는지, 그리고 라우트가 다른 라우트와 충돌을 일으키지 않을 때 라우트 우선 순위가 어떻게 작동하는지 알아보십시오. –

+0

글쎄'/ : username '은'/ : username'의 기본 제약 조건과 일치 할 것이므로'/ users'에 대한 POST와 충돌을 일으 킵니다. – rossta

관련 문제