Created
September 25, 2011 01:59
-
-
Save marklocklear/1240110 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
#controller | |
def new | |
@questions = Array.new(3) {Question.new} | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @question } | |
end | |
end | |
def create | |
@questions = params[:questions].values.collect { |question| Question.new(question) } | |
if @questions.all?(&:valid?) | |
@questions.each(&:save!) | |
redirect_to :action => 'index' | |
else | |
render :action => 'new' | |
end | |
end | |
#view | |
<%= form_tag :action => 'create' %> | |
<% @questions.each_with_index do |question, index| %> | |
<%= fields_for "questions[#{index}]", question do |f| %> | |
Name: <%= f.text_field :name %> | |
<%= f.submit %> | |
<% end %> | |
<% end %> | |
<%= form_tag %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment