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

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

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

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

Secondly, this sounds very much like a problem that Ryan Bates 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