app/controllers/rapidfire/questions_controller.rb in rapidfire-2.0.0 vs app/controllers/rapidfire/questions_controller.rb in rapidfire-2.1.0

- old
+ new

@@ -1,49 +1,69 @@ module Rapidfire class QuestionsController < Rapidfire::ApplicationController before_filter :authenticate_administrator! - respond_to :html, :js before_filter :find_question_group! before_filter :find_question!, :only => [:edit, :update, :destroy] def index @questions = @question_group.questions - respond_with(@questions) end def new - @question = QuestionForm.new(:question_group => @question_group) - respond_with(@question) + @question_form = QuestionForm.new(:question_group => @question_group) end def create form_params = params[:question].merge(:question_group => @question_group) - @question = QuestionForm.new(form_params) - @question.save + @question_form = QuestionForm.new(form_params) + @question_form.save - respond_with(@question, location: index_location) + if @question_form.errors.empty? + respond_to do |format| + format.html { redirect_to index_location } + format.js + end + else + respond_to do |format| + format.html { render :new } + format.js + end + end end def edit - @question = QuestionForm.new(:question => @question) - respond_with(@question) + @question_form = QuestionForm.new(:question => @question) end def update form_params = params[:question].merge(:question => @question) - @question = QuestionForm.new(form_params) - @question.save + @question_form = QuestionForm.new(form_params) + @question_form.save - respond_with(@question, location: index_location) + if @question_form.errors.empty? + respond_to do |format| + format.html { redirect_to index_location } + format.js + end + else + respond_to do |format| + format.html { render :edit } + format.js + end + end end def destroy @question.destroy - respond_with(@question, location: index_location) + respond_to do |format| + format.html { redirect_to index_location } + format.js + end end private + def find_question_group! @question_group = QuestionGroup.find(params[:question_group_id]) end def find_question!