0

Devise의 github에서 코드를 사용해 보았습니다. 내 서버를 검사 할 때업데이트 후 변경 리디렉션

after_filter :store_location 

def store_location 
    # store last url - this is needed for post-login redirect to whatever the user last visited. 
    if (request.fullpath != "https://stackoverflow.com/users/sign_in" && 
     request.fullpath != "https://stackoverflow.com/users/sign_up" && 
     request.fullpath != "https://stackoverflow.com/users/password") 
    session[:previous_url] = request.fullpath 
    puts 'stores location' 
    end 
end 

def after_update_path_for(resource) 
    session[:previous_url] || dashboard_path 
    puts 'after update' 
end 

의 store_location 방법에서 풋 문이 나타나지만 after_update_path_for에서 풋 문은하지 않습니다 : 내 응용 프로그램 컨트롤러, 나는있다. after_update_redirect를 작동 시키려면 어떻게해야합니까?

여기 고안 할 말하는이지만, 그것은 작동하지 않습니다 :

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update

+0

누구에게 아이디어가 있습니까? 나는 그것을 알아낼 수 없습니다. – Philip7899

답변

0

respond_with resource, :location => after_update_path_for(resource)이 업데이트 후 재 지정 경로를 설정하는 코드입니다.

class RegistrationsController < Devise::RegistrationsController 

    protected 

    def after_update_path_for(resource) 
     puts 'this is happening yoyo mama' 
     flash[:notice] = "Account succesfully updated" 
     edit_user_registration_path 
    end 
end 

경로 :

devise_for :users, :controllers => { :registrations => :registrations } 

유일한 기본 리디렉션을 변경하려면, 여기에 내가 문제를 해결하는 방법은 다음 코드

def after_update_path_for(resource_or_scope) 
    dashboard_url 
end 
+0

고마워요,하지만 그건 효과가 없습니다. 나는 그 방법이 호출되고 있다고 생각하지 않는다. puts 문을 안에 넣었고 결코 서버에 전달하지 않았습니다. – Philip7899

3

를 추가하여 응용 프로그램 컨트롤러에 다음과 같은 메소드를 오버라이드 (override) 문제는 비밀번호 변경이 성공하면 리디렉션 만 수행한다는 것입니다. 그렇지 않은 경우 리디렉션이 발생하지 않습니다. 누구든지 오류가 발생하면 리디렉션을 수행하는 방법을 알고 있습니까? 문서에서

2

:

(Object)을 after_update_path_for (자원) (보호)
기본 URL은 자원을 업데이트 한 후 사용한다. 자신의 RegistrationsController에서이 메서드를 덮어 써야합니다.

ow RegistrationsController를 만드는 것이 정확합니다. 그래도 간단한 해결책은 다음과 같습니다.

after_update_path_for#{scope}_root_path으로 보이는 전화 번호 signed_in_root_path(resource)입니다. 여기 범위는 종종 user입니다 (하지만 그렇지 않은 경우 아마 무엇인지 알 수 있습니다). '사용자'의 경우 응용 프로그램 컨트롤러에 user_root_path을 구현하고 dashboard_url을 반환하면 제대로 작동합니다.

def user_root_path 
    dashboard_url 
end 

처음에는 나에게 해킹 한 것처럼 보였지만, 나는 확실히 '괜찮습니다'라고 생각합니다. 사용자 범위의 루트 경로는 실제로 대시 보드 페이지가 될 수 있습니다.

0

ApplicationController의 경로를 재정의해도 나에게 적합하지 않지만 Users :: RegistrationsController에 추가하면 제대로 작동합니다.예를 들어 , 관련 메모에

class Users::RegistrationsController < Devise::RegistrationsController 
def after_update_path_for(resource) 
    current_user 
end 

에서, after_sign_in_path이

class Users::SessionsController < Devise::SessionsController 
def after_sign_in_path_for(resource) 
    current_user 
end 

내 경로

이처럼 보이는 SessionsController에 추가 할 수 있습니다 다음 Devise docs 당으로

devise_for :users, controllers: { 
    confirmations: "users/confirmations", 
    passwords: "users/passwords", 
    registrations: "users/registrations", 
    sessions: "users/sessions", 
    unlocks: "users/unlocks", 
} 
1

, 재정의 기본 경로와 경로를 추가하십시오. 물론 플래시 메시지를 변경하지 않는 한 플래시 메시지를 설정할 필요가 없습니다.

# Example subclass/override (registrations_controller.rb) 
class Users::RegistrationsController < Devise::RegistrationsController 

    protected 

    def after_update_path_for(resource) 
    user_path(resource) 
    end 
end 

# Example routing config (in routes.rb): 
devise_for :users, :controllers => { :registrations => :registrations } 
관련 문제