2017-05-23 6 views
0

두 개의 페이지가 Devise의 업데이트 사용자 양식을 렌더링합니다. 클래식 편집자 (사용자/수정) 및 전체 편집 양식의 일부만있는 '/ 페이지'페이지. 양식이 하나 또는 다른 페이지에 제출되는지 여부에 따라 두 가지 다른 after_update_path를 갖고 싶습니다. 나는 몇 가지를 시도하지만 아무도는 노력하고 있습니다 ... 나는 다음과 같은 오류가 Rails Devise : 두 가지 다른 after_update_path_for

def after_update_path_for(resource) 
    if current_page?('/page') 
     :page 
    else 
     :root_path 
    end 
    end 

:

undefined method `current_page?' for #RegistrationsController:0x007fe9db304e28 Did you mean? current_user

가 그렇게 할 수 있다면 어떤 생각?

답변

1

ActionView::Helpers::UrlHelper을 포함해야하는 것처럼 보입니다. 메서드가 해당 컨트롤러에서 정의되지 않았기 때문입니다.

class Users::RegistrationsController < Devise::SessionsController 
    include ActionView::Helpers::UrlHelper 

    def after_update_path_for(resource) 
    if current_page?('/path') 
     render :page 
    else 
     render :root_path 
    end 
    end 
end 

여기는 docs for the method입니다. 위의 설명을 참고 : 어떤 이유로이 레일 3에서 작동하지 않는 경우

The default url to be used after updating a resource. You need to overwrite this method in your own RegistrationsController.

, 당신은 이런 식으로 뭔가를 시도 할 수 :

def after_update_path_for(resource) 
    if params[:action] == 'my_action' && params[:controller] == 'my_controller' 
    render :page 
    else 
    render :root_path 
    end 
end 
+0

감사합니다 제임스, 작동! – AlphaNico

+0

안녕하세요. 도와 줄 수있어서 기뻐! :-) –