Skip to content

Instantly share code, notes, and snippets.

@bastianccm
Created February 26, 2020 13:21
Show Gist options
  • Save bastianccm/8d3b2211f7b904bf295b5117aad4441d to your computer and use it in GitHub Desktop.
Save bastianccm/8d3b2211f7b904bf295b5117aad4441d to your computer and use it in GitHub Desktop.
//...
func (c *controller) results(ctx context.Context, request *web.Request) web.Result {
questionID, err := strconv.Atoi(request.Params["question_id"])
if err != nil {
return c.responder.ServerError(err)
}
var viewData struct {
Question Question
}
if c.db.Preload("Choices").First(&viewData.Question, questionID).RecordNotFound() {
return c.responder.NotFound(gorm.ErrRecordNotFound)
}
return c.responder.Render("results", viewData)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment