dynamic models

Hi

In my app , a user can create a set of question then a table is
dynamily created , in the database,to store the answers of the
questions. the name of the table is answers_x (x is the id of the
questionniare).

Is it possible to dynamicly create a model, to handle the answer_x
tables ?? I can't manually create a model then restart the server.

jef wrote:

Hi

In my app , a user can create a set of question then a table is
dynamily created , in the database,to store the answers of the
questions. the name of the table is answers_x (x is the id of the
questionniare).

Is it possible to dynamicly create a model, to handle the answer_x
tables ?? I can't manually create a model then restart the server.

Why a different table per set of questions?

Sounds like what you need is actually are more generic models (Quizzes
and Quizitems?) that stores lists of questions and answers.

Assuming you have a User model defined somewhere else...

User
  has_many :quizzes

Quiz
  belongs_to :user
  has_many :quizitems

Quizitem
  belongs_to :quiz

where a quizitem contains a question and an answer... maybe points if
you're scoring them somehow.

If you really do want to do this, you can do it with the eval method.

eval will execute a string as ruby code.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #4 parts a and b now available!
http://sensei.zenunit.com/

can you give me an example julian

I know that eval('puts "foo"') print the the foo string. But I don't
know how to generate a new model.
Thank you.

Generating a new model for each question is not the right way to do
this. I feel you are making things way too hard. There is no reason you
can't just use a solution similar to what Ar Chron explained. In short,
create a Question and Answer model. Just store the answers as string and
the questions as strings and then store the type of the question /
answer as well and simply cast the answer to the type. or go the
polymorphic route and have an answer model for each possible answer
type. Bottom line, creating arbitrary dynamic models for each question
is simply not the path to take.