Storing Objects in a Session in Rails

后端 未结 4 1155
一个人的身影
一个人的身影 2020-12-01 08:27

I have always been taught that storing objects in a session was a bad idea. Instead IDs should be stored that retrieve the record when needed.

However, I have an ap

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 09:19

    Rails tends to encourage RESTful design, and using sessions isn't very RESTful. I'd probably make a Quiz resource that has a bunch of words, as well as a current_word. This way, when they come back, you'll know where they were.

    Now, REST isn't everything (depending on who you talk to), but there's a pretty good case against large sessions. Remember that sessions write things to and from disk, and the more data that you're writing, the longer it takes to read back...

提交回复
热议问题