0

I have a Rails Application where I want to present user with a sequence of Questions in a particular order. A user cannot proceed to the next question unless he has answered the previous one.

Here are some design issues I need help on for an efficient implementation:

To fetch a list of questions for a user I need to make an expensive db call. Once for a new session, the list if fetched I simply want the user to see the questions in a particular order starting from the first question. If the user had attempted some questions in a pervious session he will jump to the question he last left off. How to implement it efficiently? I believe I need caching here.

On rendering the views :

How to render the view for this feature? I can have a controller with the initial question template. When user attempts the question, should I have question-answer options text updating with AJAX? Do I have to use jquery for the purpose or any Rails helper could be of help here?

Any design help, rails features-gems I could make use of will be welcomed.

4

1 回答 1

1

我的回答并不特定于 Ruby on Rails,但它应该仍然有效。

首先,我不会加载您可能不会提前使用的数据。如果您有 10 个问题,并且一次只显示一个,那么我只会加载第一个问题,然后在用户完成第一个问题后,继续加载第二个问题。无需加载所有十个,因为用户可能永远不会完成第 10 个问题。

假设用户过早离开,您只需进行 AJAX 调用即可从您离开的地方继续。

我同意你应该缓存这些问题。

步骤将如下所示:

  1. 第一个问题 - 通过 AJAX 加载。通过 AJAX 调用保存的答案和进度。
  2. 如果 (1),则通过 AJAX 加载第二个问题。通过 AJAX 调用保存的答案和进度。
  3. 重复直到问题完成。

通过这种方式,您可以使用用户/登录信息进行 AJAX 调用以从您离开的地方继续。我想这将使您的数据库调用成本更低。

于 2013-04-04T04:09:12.680 回答