Skip to content

Instantly share code, notes, and snippets.

@jamesalmond
Last active December 18, 2015 22:08
Show Gist options
  • Save jamesalmond/5851952 to your computer and use it in GitHub Desktop.
Save jamesalmond/5851952 to your computer and use it in GitHub Desktop.
<%= 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 %>
class Survey < ActiveRecord::Base
has_many :questions
has_many :answers, through: :questions
accepts_nested_attributes_for :answers
end
class User < ActiveRecord::Base
accepts_nested_attributes_for :answers
has_many :answers
end
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