Created
August 24, 2017 23:50
-
-
Save staycreativedesign/fe8d54980e6f8dc01861a9a8ef1232fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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