2017-05-23 53 views
0

我有兩個頁面呈現Devise的更新用戶窗體。經典之作(用戶/編輯)和'/ page'頁面,只是完整編輯表格的一部分。我希望有兩個不同的after_update_path,不管表單是提供給一個還是另一個頁面。我試過幾件事情,但我沒有正在...Rails設計:兩種不同的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。注意上面的註釋:

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

如果由於某種原因,這並不在軌道3個工作,你可以嘗試做這樣的事情:

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

不客氣!樂於幫助! :-) –

相關問題