Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created August 24, 2017 23:50
Show Gist options
  • Save staycreativedesign/fe8d54980e6f8dc01861a9a8ef1232fa to your computer and use it in GitHub Desktop.
Save staycreativedesign/fe8d54980e6f8dc01861a9a8ef1232fa to your computer and use it in GitHub Desktop.
class Questionnaire < ApplicationRecord
has_many :questions
has_many :member_questionnaires
has_many :users, through: :member_questionnaires
accepts_nested_attributes_for :questions
end
class Question < ApplicationRecord
belongs_to :questionnaire
has_one :questionnaire_answer
accepts_nested_attributes_for :questionnaire_answer
end
class QuestionnaireAnswer < ApplicationRecord
belongs_to :question
end
%h1
questionnaires#edit
= form_for @answer do |f|
- @questionnaire.questions.each.with_index do |q, index|
%h1
= q.description
= f.fields_for :questions, q do |question_fields|
= question_fields.fields_for :questionnaire_answer, q.build_questionnaire_answer do |answer_fields|
= answer_fields.text_field :description, id: index
= f.submit "Save answers"
{
"utf8" => "✓",
"questionnaire_answer" => {
"questions" => {
"questionnaire_answers" => {
"description" => "Wayfarers park pug ennui letterpress irony."
}
}
},
"commit" => "Save answers",
"controller" => "questionnaire_answers",
"action" => "create"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment