Skip to content

Instantly share code, notes, and snippets.

@anveo
Forked from salbito/gist:639680
Created October 22, 2010 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anveo/639702 to your computer and use it in GitHub Desktop.
Save anveo/639702 to your computer and use it in GitHub Desktop.
def new
@survey = Survey.find params[:survey_id]
@questions = @survey.questions(:include => :answers).map{|q| q.answers.build}
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @answer }
end
end
def update
@survey.find params[:id]
@survey.update_attributes params[:survey]
redirect_to wherever
end
_form.html.haml
= form_for @survey do |f|
- f.fields_for :questions do |qf|
= qf.text_field :question
- qf.fields_for :answers do |af|
= af.text_field :answer
.actions
= f.submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment