跟踪"谈话"流入西纳特拉 [英] Tracking "conversation" flow in Sinatra

查看:114
本文介绍了跟踪"谈话"流入西纳特拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个职位。我处理消息的API,但是它不是Twilio API。有问题的服务器具有存储Cookie没有明确的支持,所以我不知道我怎么能会话状态/数据存储无论是在内存中,我的服务器上,或在某种程度上数据库中。

Consider this post. I'm dealing with messaging API, however it's not the Twilio API. The server in question has no explicit support for storing cookies so I'm wondering how I can store the session state/data either in memory, on my server or in a database somehow.

时的那样简单使用机架::会议::游泳池作为cookie的方法是什么?我找不到任何好的TUTS或例子。

Is it as simple as using Rack::Session::Pool as the cookie method? I can't find any good tuts or examples.

推荐答案

我想你混淆了cookie和会话了一下。

I think you mix up cookies and sessions a bit.

饼干

一个cookie,也被称为一个HTTP cookie,网络Cookie或浏览器cookie,是一小片从一个网站发送并存储在用户的Web浏览器,而用户浏览该网站的数据。

A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. source

这意味着有客户端的网站,在它的信息的小文本文件。这意味着它也许不是保存明文敏感内容最好的主意。你必须知道,它的客户端手,如果它接受Cookie。

This mean there are small text files on client site with information in it. This mean it's maybe not the best idea to save sensitive content in clear text. And you must be aware, that it's in client hand if it accept cookies.

在西纳特拉它们都建在,但命名会话(我知道,有点混乱,这是因为cookie是客户端Web会话)

In sinatra they are built in but named session (I know, a bit confusing, this is because cookies are Client side web sessions)

举例code

require 'sinatra'
enable :sessions

get '/' do
  session["value"] ||= "Hello world!"
  "The cookie you've created contains the value: #{session["value"]}"
end

和有西纳特拉::在西纳特拉的Contrib 饼干。我不知道为什么这甚至存在,但值得一提的。

And there is Sinatra::Cookies in Sinatra Contrib. I have no clue why this even exist, but it worth mentioning.

会议

会话或显式服务器端Web会话是为每个客户端是坚持服务器站点的状态。

Sessions or explicit Server side web sessions is a state for each client which is hold on server site.

举例code

require 'sinatra'
use Rack::Session::Pool

get '/' do
  session["value"] ||= "Hello world!"
  "The server side session you've created contains the value: #{session["value"]}"
end

结论和放大器; TL; DR

不知道什么你到底努力实现,这是很难说这会为你工作好。此外,甚至有可能对两个组合和状态保存到数据库。因此,它取决于你试图达到的目标。

Without knowing what you exactly try to achieve, it's hard to tell which will work better for you. Additionally there is even possible to combine both and save the state to a Database. So it depend on what you try to achieve.

这篇关于跟踪"谈话"流入西纳特拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆