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?
By default rails uses cookies to store the session data. All data is stored in the client, not on the server.
The Session Storage basically consists of 4 main methods. setItem(key, value): This method is used to set the value into the Session Storage based on the key. getItem(key): This method is used to get the value that is stored into the Session Storage. It takes a key and returns the value.
Yes you can save the file in session object.
Rails provides a session object for each user that accesses the application. If the user already has an active session, Rails uses the existing session. Otherwise a new session is created. Read more about sessions and how to use them in Action Controller Overview Guide.
To store something in a session you can do:
session[:answer] = "some answer"
Then you can call the answer with:
session[:answer]
Or you could use HTML5 localstorage:
<script> localStorage.setItem("essay", "text"); localStorage.getItem("essay"); // => "text" </script>
Sessions
Rails sessions are meant to keep consistency throughout your app
IMO, sessions are best used for storing "snippets" of data (such as a single object, ids
etc), and are best used for these types of functions:
Database
What you've asked is how you store people's answers in sessions
I would argue you should store them in a database, but secure that DB with authentication (such as Devise):
#app/controllers/answers_controller.rb def new @answer = Answer.new end def create @answer = Answer.new(answer_params) @answer.save end private def answers_params params.require(:answer).permit(:body, :question_id).merge(user_id: current_user.id) end
This will allow you to store the answers in a database (the database can be on your local computer, local Intranet, or anywhere you want)
Security
The key for you will be to secure your data
This is called Authentication
, and without going into huge detail, here's a great resource for you:
http://railscasts.com/episodes/250-authentication-from-scratch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With