Created
June 13, 2013 21:21
-
-
Save adamjgrant/5777487 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
###### routes.rb | |
resources :surveys do | |
resources :questions do | |
resources :responses | |
end | |
end | |
###### questions/new.html.erb | |
<%= form_for([@survey, @survey.questions.build]) do |f| %> | |
<% if @question.errors.any? %> | |
<div id="errorExplanation"> | |
<h2><%= pluralize(@question.errors.count, "error") %> prohibited this question from being saved: </h2> | |
<ul> | |
<% @question.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :question %><br /> | |
<%= f.text_field :question %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> | |
###### questions_controller.rb | |
def create | |
@question = Question.new(params[:question]) | |
@question.survey_id = Survey.find(params[:survey_id]) | |
respond_to do |format| | |
if @question.save | |
format.html { redirect_to(@question, | |
:notice => 'question was successfully created.') } | |
format.json { render :json => @question, | |
:status => :created, :location => @question } | |
else | |
format.html { render :action => "new" } | |
format.json { render :json => @question.errors, | |
:status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment