Fwd: Multiple records in table

In my project there are n no. of questions… Following is an example of
same… I have brought them via loop in my page,
Q1: Question 1
a. answer 1
b. answer 2
c. answer 3
d. answer 4

Q2: Question 2
a. answer 1
b. answer 2
c. answer 3
d. answer 4

and so on…

Submit(button)

Also one option will be selected at a time, I have used radio buttons
for
answers
Now the above data need to be stored in a table say answers_table where
it
will be saving question_id and answer_id…and on one submit action all
the questions and answer should be inserted in database like this
*
answers_table* :
id question_id answer_id
1 1 a
2 2 c

I am facing this issue from since 2 days

On 8 August 2012 07:50, rubyrails9 [email protected] wrote:

Q2: Question 2
answers
Now the above data need to be stored in a table say answers_table where it
will be saving question_id and answer_id…and on one submit action all the
questions and answer should be inserted in database like this

answers_table :
id question_id answer_id
1 1 a
2 2 c

I am facing this issue from since 2 days

First, don’t call the table answer_table. Table name should be plural
so if it has answers in then call it answers.

Second, you have not actually asked a question that we can answer,
just vaguely described the whole requirement. What exactly are you
having problems with? Database design? The view? Controller code?
Model code? You must ask specific questions that we can answer. Also
you have not actually told us what models you have and what their
releationships are (has_many, belongs_to etc.)

Colin

On Aug 9, 2012, at 7:25 AM, Colin L. wrote:

Also one option will be selected at a time, I have used radio buttons for
I am facing this issue from since 2 days

Colin

Secondly, this sounds very much like a problem that Ryan B. covers in
his two-part nested forms Railscast. He takes it a bit further than your
example, in that the questions and the answers are completely
configurable, rather than a fixed set of 4 answers. You might want to
watch those for inspiration. The Rails version is a few versions back,
but you should grasp the basics of how the relationships and the views
are configured. Nothing about Rails 3 vs. 3.1 or 3.2 should change that.

Walter

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs