I am writing an optics review program that has 2 types of questions. "Static" questions are just regular questions stored in a "questions" table along with their associated correct answers and explanations. "Generated" questions are generated by a "method" I write. When a generated question is picked, the method I wrote is called and it returns an "instance" of the question, its correct answer, and its explanation. Each time the question is called it generates a slightly different version of the question. I plan to have hundreds of these methods. Currently each is a separate file. I do not know what the best approach to storing and accessing these files/methods is. Is the a correct rails way to do this? I would appreciate any help, even pointing me in the right direction would be a great help! Thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 25 August 2012 18:40, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> "Generated" questions are generated by a "method" I write. When a > generated question is picked, the method I wrote is called and it > returns an "instance" of the question, its correct answer, and its > explanation. Each time the question is called it generates a slightly > different version of the question. I plan to have hundreds of these > methods. Currently each is a separate file.What do these generated methods look like? Are they very similar to each other? Do they follow some sort of pattern? Could that be turned into some form of configuration information? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Saturday, 25 August 2012 12:44:00 UTC-5, Michael Pavling wrote:> > On 25 August 2012 18:40, Dave Castellano <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org<javascript:>> > wrote: > > "Generated" questions are generated by a "method" I write. When a > > generated question is picked, the method I wrote is called and it > > returns an "instance" of the question, its correct answer, and its > > explanation. Each time the question is called it generates a slightly > > different version of the question. I plan to have hundreds of these > > methods. Currently each is a separate file. > > > What do these generated methods look like? Are they very similar to > each other? Do they follow some sort of pattern? Could that be turned > into some form of configuration information? >I think I would rather store the information as a sprintf string in the same table and then grep for %s and/or add an extra column on the table that holds the type of dynamic question it is so that you can have a single method that transforms itself based on that column and then just does something like `"hello %s, how are you?" % ''Jordon''` but you can do that for complete phrases and such. This makes it so you have a single method for both dynamic and "static"... Or you could do that with I18n but I still prefer to keep those in the database and cache them into memory as I pull them out of the database. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/3dG5r7Dno5EJ. For more options, visit https://groups.google.com/groups/opt_out.
They are all very different, although all return a similar hash of arguments. Here is an example... def vergence_v u = (rand(2..6)).round(2) u_vergence =((1/(u*0.01)).round(2)) p = rand((u_vergence + 0.1) ..(u_vergence + 0.7)).round(2) v_vergence = (p - u_vergence).round(2) v = (1/v_vergence).round(2) question = "A slide is placed #{u} cm to the left of a +#{p} D lens. At what distance (in meters) will the screen need to be placed to the right of the lens to have the image be in perfect focus?" answer = "Answer = #{v} meters" anno = "Solution: Use the formula U + P = V. U = Vergence of light rays from the object entering the lens P = Power of the lens in diopters V = Vergence of light rays leaving the lens and forming the image where u = #{u} cm P = #{p} D (1) Solve for V V = U + P (2) Solve for U Since Vergence = 1/distance in meters, we need to convert all units from centimeters to meters. u = #{u} cm = #{u} X 0.01 = #{((u)*0.01).round(2)} m U is negative because it is a real object and light rays DIVERGE from REAL objects U = -1.0/#{(u*0.01).round(2)}m = #{(-1.0/(u*0.01)).round(2)}D (3) Solve for V V = U + P = #{(-1.0/(u*0.01)).round(2)}D + #{p}D = #{((-1.0/(u*0.01)) + p).round(2)}D (4) Solve for v v = 1/V = #{(1/v_vergence).round(2)}cm" formatted = {"question_1" => question, "answer_1" => answer, "anno_1" => anno} end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
They are all very different, although all return a similar hash of arguments. Here is an example... def vergence_v u = (rand(2..6)).round(2) u_vergence =((1/(u*0.01)).round(2)) p = rand((u_vergence + 0.1) ..(u_vergence + 0.7)).round(2) v_vergence = (p - u_vergence).round(2) v = (1/v_vergence).round(2) question = "A slide is placed #{u} cm to the left of a +#{p} D lens. At what distance (in meters) will the screen need to be placed to the right of the lens to have the image be in perfect focus?" answer = "Answer = #{v} meters" anno = "Solution:......" formatted = {"question_1" => question, "answer_1" => answer, "anno_1" => anno} end Could this be saved as a string in the database, and then be written to a temp file and "required" by the model when it is needed? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.