Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:06:17+00:00 2026-05-31T07:06:17+00:00

i have a module that needs to save a solution(for a quiz) value. This

  • 0

i have a module that needs to save a solution(for a quiz) value. This is trivial, of course, when the solution is simply a value like ‘342’. However, there are cases where there are some dynamic calculations taking place. For instance, if a user enters the value 100, it could be that in order to get the correct solution, i would first have to calculate (x*2) == 300. Therefore, if x=100, the solution would be wrong.

Unluckily, i cannot store such calculations in a database(at least based on what i know). One thing that i could do is add specific solution methods for particular quizzes in my Quiz model. However, i don’t like this at all. It’s making the class very difficult to maintain, so i quickly abandoned that idea.

Another idea would be to save a new class object in every quiz that needs that. This class will include all the methods needed, that just verify the calculations(either with STI or a module, most probably the latter is easier). I like this idea better and i think that it’s most probably what i am going to implement, but before doing so, i would like to hear your ideas about it.

How would you go about it ?

NOTICE that a big problem that arises from creating a module or a class to handle all the solutions, is the case where i would like to have multiple quiz authors in the future. If they could create their own challenges, it would be virtually impossible to create dynamic solutions for them this way. Or it would be a hell for me to supervise every such entry and manually create the needed code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:06:18+00:00Added an answer on May 31, 2026 at 7:06 am

    i cannot store such calculations in a database(at least based on what i know)

    Sure you can. Code is just text and ruby is a dynamic language. You could store your correct solution evaluation expression as text, then turn it into code with eval.

    So, if that text field was the evaluation_expr field of a question object containing something like “(x.to_i*2) == 300” (expecting x to be the supplied answer):

    evaluator = eval "lambda { |x| #{question.evaluation_expr} }"
    got_it_right = evaluator.call( params[:x] )
    

    This gives you the ability to have arbitrarily complex ruby expressions for calculating correct answers to your quiz question and store them in a database.

    Unfortunately, this is also a security risk if you’re accepting the entry of these expressions from untrusted users, because you are going to execute what they enter as ruby in your service. Of course that’s a problem endemic to multiple quiz authors if they have to write code to express their questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ module that needs to get information from other classes, without
I have a module that imports an Access table to MS Office Excel. This
Currently I have a static class that I use as my logging module. I’ve
I am creating a module that needs to tag nodes with taxonomy terms when
I have the following code in a custom module to save a session_id for
I have an Excel worksheet that has 30k+ rows. I'd like to cut the
I have a module that has a function whose prototype is similar to that
I have a two part question: Part 1 I have a module that has
So I have this form that has tons of text boxes, combo boxes, etc.
I have a Web Service ( model-layer ) which communicates with Database. This module

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.