Home Nested Form Ruby. How to answer forms
Reply: 0

Nested Form Ruby. How to answer forms

user1158 Published in July 18, 2018, 10:24 pm

I want to implement a form generator solution. I created 4 models :

Formulaire: name, description

Questions: formulaire_id,nom,typequestion

Answers: question_id,content

Poll: formulaire_id,question_id, answer_id, nom

In my Poll, I want to insert user responses to my forms.

 <%= form_for([@formulaire, @formulaire.polls.new]) do |f| %>

 <% for question in @formulaire.questions %>

    <%=h question.nom %> 
    <% for answer in question.answers %>        
       <%= radio_button("poll", "answer_id", answer.id) %>  <%=h answer.content %> <br/>
       <%= f.hidden_field :question_id, value: question.id %>

    <% end %>

<% end %>

My routes.rb :

  resources :formulaires do
    resources :polls

The problem is that my hidden_field :question_id always inserts the last Question in my DB. Whereas I want to insert the id of the current answer.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.324846 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO