Skip to content

Instantly share code, notes, and snippets.

@bastianccm
Created February 26, 2020 13:17
Show Gist options
  • Save bastianccm/1ceb95fe0ed6bd28461e7c7a9e8ddbd5 to your computer and use it in GitHub Desktop.
Save bastianccm/1ceb95fe0ed6bd28461e7c7a9e8ddbd5 to your computer and use it in GitHub Desktop.
//...
func (c *controller) detail(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
ErrorMessage string
}
if c.db.Preload("Choices").First(&viewData.Question, questionID).RecordNotFound() {
return c.responder.NotFound(gorm.ErrRecordNotFound)
}
return c.responder.Render("detail", viewData)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment