Rails:如何在会话中存储数据? [英] Rails: How to store data in session?

查看:30
本文介绍了Rails:如何在会话中存储数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Rails 制作一个写作考试练习网络应用.问题是,如果用户的答案被提交到互联网上,他们很容易被 ETS 检测到.所以当用户在实际测试中再次写出他们的答案时,ETS 会认为他们是在应对网上的答案,给他们一个相当低的分数.

I'm making an writing exam practice web app in Rails. The problem is that if users' answers are submited to the Internet, they will easily be detected by ETS. So when users write their answers again in real test, ETS will think they are coping answers from Internet and give them a fairly low score.

我对此的方法是在会话中存储用户的文章.所以它根本不会上传到互联网.但是,如何在会话中存储对象?

My approach to this, is to store users' eassay in session. So it will not be upload to Internet at all. But, how can I store an object in session?

推荐答案

要在会话中存储内容,您可以执行以下操作:

To store something in a session you can do:

session[:answer] = "some answer"

然后你可以打电话给答案:

Then you can call the answer with:

session[:answer]

或者你可以使用 HTML5 本地存储:

Or you could use HTML5 localstorage:

<script>
  localStorage.setItem("essay", "text");
  localStorage.getItem("essay"); // => "text"
</script>

这篇关于Rails:如何在会话中存储数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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