我有一个控制器,我从中创建一个 cookie,其中包含有关我正在开发的游戏的信息。我遇到的问题是,当我在该控制器中使用另一个操作时,值会发生变化。
这是我的控制器:
def new
@videos = Video.order("RANDOM()").limit(2)
if !cookies.signed[:game]
cookies.signed[:game] = {
:value => @videos,
:domain => 'localhost',
:secure => !(Rails.env.test? || Rails.env.development?)
}
end
end
def start_game
respond_to do |format|
format.js
end
end
start_game.erb.js
console.log('<%= cookies.signed[:game].first.titel %>') # This should print out the same value but it doesn't do that.
新的.html.erb
...
<%= button_to "game", { :action => "start_game" }, { :remote => true, :form_class => "test_button" } %>
我可以检查是否存在已签名的 cookie 吗?