Skip to content

Instantly share code, notes, and snippets.

@RicharCor
Created January 25, 2019 06:25
Show Gist options
  • Save RicharCor/ba3a07c3c330a7a29332ff0655a11638 to your computer and use it in GitHub Desktop.
Save RicharCor/ba3a07c3c330a7a29332ff0655a11638 to your computer and use it in GitHub Desktop.
Controlador respondents
#No olvides las asociaciones en los modelos
class RespondentsController < ApplicationController
#info del controlador
before_action :find_survey, only: [:create]
#info del controller
def create
@respondent = @survey.respondents.new(respondent_params)
@respondent.survey = @survey
respond_to do |format|
if @respondent.save
format.html { redirect_to @respondent.survey, notice: 'Respondent was successfully created.' }
format.json { render :show, status: :created, location: @respondent }
else
format.html { render :new }
format.json { render json: @respondent.errors, status: :unprocessable_entity }
end
end
#info del controlador
private
#info del controlador
def find_survey
@survey = Survey.find(params[:survey_id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment