2012-07-18 51 views
0

我讓用戶能夠查看公共頁面的預覽,即使他們沒有登錄。公共頁面具有登錄鏈接,並且在用戶重定向到登錄頁面並登錄之後,他們被重定向回存儲的public_page。當用戶從視圖導航時調用Rails控制器方法

我正在尋找的是當用戶從他們正在預覽而未登錄的public_page導航離開時調用clear_location方法的一種方法。現在,如果用戶訪問預覽頁面然後返回到我的主頁並從那裏登錄,他們被引導回他們正在查看的預覽頁面。

def page_public 
    store_location 
end 

def store_location 
    session[:current_location] = request.fullpath 
end 

def clear_location 
    session[:current_location] = nil 
end 

回答

2

聽起來好像您只是想在訪問任何不是登錄頁面的頁面時調用clear_location。 假設是正確的,你可能想在你的ApplicationController中,您將跳過對參與伐木行動的before_filter也許是這樣的:

class ApplicationController < ActionController::Base 
    before_filter :clear_location 

    ... 

    def clear_location 
    session[:current_location] = nil 
    end 
end 

class LoginController < ApplicationController 
    skip_before_filter :clear_location, :only => [:login] 

    ... 
end 

當然,我不知道什麼控制器處理您的登錄,或者確切地說涉及哪些行動,但是沿着這些方向的事情應該完成工作。

+0

是的,或多或少...謝謝! – 2012-07-19 00:31:01

相關問題