// Update changes a Contact in the DB. This function is mapped to
// the path PUT /contacts/{contact_id}
Update changes a Contact in the DB. This function is mapped to
the path PUT /contacts/{contact_id}
// Update changes a Contact in the DB . This function is mapped to // the path PUT / contacts / { contact_id }
func (v ContactsResource) Update(c buffalo.Context) error {
	tx := c.Value("tx").(*pop.Connection)
	contact := &models.Contact{}
	if err := tx.Find(contact, c.Param("contact_id")); err != nil {
		return c.Error(404, err)
	}
	if err := c.Bind(contact); err != nil {
		return errors.WithStack(err)
	}
	verrs, err := tx.ValidateAndUpdate(contact)
	if err != nil {
		return errors.WithStack(err)
	}
	if verrs.HasAny() {
		c.Set("contact", contact)
		c.Set("errors", verrs)
		return c.Render(422, render.R.HTML("contacts/edit.html"))
	}
	c.Flash().Add("success", "Contact was updated successfully")
	return c.Redirect(302, "/contacts/%s", contact.ID)
}
func ( v ContactsResource ) Update ( c buffalo . Context ) error { tx := c . Value ( " " ) . ( * pop . Connection ) contact := & models . Contact { } if err := tx . Find ( contact , c . Param ( " " ) ) ; err != nil { return c . Error ( 404 , err ) } if err := c . Bind ( contact ) ; err != nil { return errors . WithStack ( err ) } verrs , err := tx . ValidateAndUpdate ( contact ) if err != nil { return errors . WithStack ( err ) } if verrs . HasAny ( ) { c . Set ( " " , contact ) c . Set ( " " , verrs ) return c . Render ( 422 , render . R . HTML ( " " ) ) } c . Flash ( ) . Add ( " " , " " ) return c . Redirect ( 302 , " " , contact . ID ) }
Update changes a Contact in the DB.
Update changes a Contact in the DB .
// Get the DB connection from the context // Allocate an empty Contact // Bind Contact to the html form elements // Make contact available inside the html template // Make the errors available inside the html template // Render again the edit.html template that the user can // correct the input. // If there are no errors set a success message // and redirect to the contacts index page