Maurício Linhares là chính xác, tuy nhiên, tôi muốn thêm một số detai l bởi vì tôi không nghĩ rằng nó rõ ràng những phương pháp bạn cần phải thực hiện.
Bạn có thể kế thừa từ ActionDispatch::Session::AbstractStore, nhưng được kế thừa từ Rack::Session::Abstract::ID, đây là nơi tốt để tìm kiếm các phương pháp bạn cần triển khai. Cụ thể, từ Rack::Session::Abstract::ID:
# All thread safety and session retrival proceedures should occur here.
# Should return [session_id, session].
# If nil is provided as the session id, generation of a new valid id
# should occur within.
def get_session(env, sid)
raise '#get_session not implemented.'
end
# All thread safety and session storage proceedures should occur here.
# Should return true or false dependant on whether or not the session
# was saved or not.
def set_session(env, sid, session, options)
raise '#set_session not implemented.'
end
# All thread safety and session destroy proceedures should occur here.
# Should return a new session id or nil if options[:drop]
def destroy_session(env, sid, options)
raise '#destroy_session not implemented'
end
Tôi đã viết đơn giản file-based session store làm thử nghiệm.
Nguồn
2012-08-13 15:37:15
Thừa kế 'Giá :: Phiên :: Tóm tắt :: ID' đã không được chấp nhận. Bây giờ nó sẽ là 'Rack :: Session :: Abstract :: Persisted'. –
Ví dụ thực tế khác là đá quý ['redis-session-store'] (https://github.com/roidrage/redis-session-store). –