Created
January 25, 2019 06:25
-
-
Save RicharCor/ba3a07c3c330a7a29332ff0655a11638 to your computer and use it in GitHub Desktop.
Controlador respondents
This file contains hidden or 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
#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