Last active
December 18, 2015 22:08
-
-
Save jamesalmond/5851952 to your computer and use it in GitHub Desktop.
This file contains 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
<%= form_for :question, :url => step1_path do -%> | |
<% for question in @questions %> | |
<%= fields_for "answers[]", Answer.new(question_id: question.id) do |li_fields| %> | |
<%= li_fields.label :title, question.title %> | |
<%= li_fields.hidden_field :question_id %> | |
<%= li_fields.text_field :weight %> | |
<% end %> | |
<% end %> | |
<%= submit_tag "Create line items" %> | |
<% end %> |
This file contains 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 Survey < ActiveRecord::Base | |
has_many :questions | |
has_many :answers, through: :questions | |
accepts_nested_attributes_for :answers | |
end |
This file contains 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 User < ActiveRecord::Base | |
accepts_nested_attributes_for :answers | |
has_many :answers | |
end |
This file contains 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 Step1Controller < ApplicationController | |
def new | |
@questions = Question.all() | |
end | |
def create | |
if current_user | |
current_user.update_attributes!(params[:question]) | |
else | |
survey = Survey.first | |
survey.update_attributes!(params[:question]) | |
end | |
flash[:notice] = 'Reports were successfully updated.' | |
redirect_to 'step1' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment