active_record_store和cookie_store之间的会话差异

时间:2023-01-12 13:26:48

In rails 2.3, I changed session store from cookies to active_record. I compared session.inspect between the two stores. In cookie_store, it showed a lot of info but in active_record_store it showed nothing(just {}).

在rails 2.3中,我将会话存储从cookie更改为active_record。我比较了两家商店之间的session.inspect。在cookie_store中,它显示了很多信息,但在active_record_store中它没有显示任何内容(只是{})。

My main concert is session_id. You can't get session[:session_id] in active_record_store. Is this right behavior? Do I have to see session differently according to session store option?

我的主要音乐会是session_id。您无法在active_record_store中获取会话[:session_id]。这是正确的行为吗?我是否必须根据会话存储选项以不同方式查看会话?

Sam

1 个解决方案

#1


Why are you trying to get access to session_id? You should treat the session as a hash that Rails creates for you. So for instance, if you did:

你为什么试图访问session_id?您应该将会话视为Rails为您创建的哈希。例如,如果您这样做:

def some_action
  session[:name] = "wycats"
end

In a subsequent action you would be able to do:

在随后的行动中,您将能够:

def some_action
  session[:name] # will be "wycats"
end

In other words, the session is a Hash that persists across requests.

换句话说,会话是一个持久存在请求的哈希。

#1


Why are you trying to get access to session_id? You should treat the session as a hash that Rails creates for you. So for instance, if you did:

你为什么试图访问session_id?您应该将会话视为Rails为您创建的哈希。例如,如果您这样做:

def some_action
  session[:name] = "wycats"
end

In a subsequent action you would be able to do:

在随后的行动中,您将能够:

def some_action
  session[:name] # will be "wycats"
end

In other words, the session is a Hash that persists across requests.

换句话说,会话是一个持久存在请求的哈希。