我正在分配一個整個用戶對象在會話中舉行......這是不好的?軌道如何存儲會話數據?我有一種感覺,這是一個壞主意。我應該只在會話中存儲user_id嗎?rails會話助手(這是不好的)
module SessionsHelper
def sign_in(user)
session[:user] = user
end
def current_user
session[:user]
end
def sign_out
session[:user] = nil
end
end
EDIT(我認爲這是更好)
module SessionsHelper
def sign_in(employee)
session[:employee_id] = employee.id
@employee = employee
end
def current_employee
if session[:employee_id]
@employee||=Employee.first(session[:employee])
end
end
def sign_out
session[:employee_id] = nil
@employee = nil
end
end