// Update changes a Activity in the DB. This function is mapped to
// the path PUT /activities/{activity_id}
Update changes a Activity in the DB. This function is mapped to
the path PUT /activities/{activity_id}
// Update changes a Activity in the DB . This function is mapped to // the path PUT / activities / { activity_id }
func (v ActivitiesResource) Update(c buffalo.Context) error {
	tx, ok := c.Value("tx").(*pop.Connection)
	if !ok {
		return fmt.Errorf("no transaction found")
	}
	activity := &models.Activity{}
	if err := v.scope(c).Find(activity, c.Param("activity_id")); err != nil {
		return c.Error(http.StatusNotFound, err)
	}
	if err := c.Bind(activity); err != nil {
		return err
	}
	verrs, err := tx.ValidateAndUpdate(activity)
	if err != nil {
		return err
	}
	if verrs.HasAny() {
		return responder.Wants("html", func(c buffalo.Context) error {
			c.Set("errors", verrs)
			c.Set("activity", activity)
			return c.Render(http.StatusUnprocessableEntity, r.HTML("/activities/edit.plush.html"))
		}).Wants("json", func(c buffalo.Context) error {
			return c.Render(http.StatusUnprocessableEntity, r.JSON(verrs))
		}).Wants("xml", func(c buffalo.Context) error {
			return c.Render(http.StatusUnprocessableEntity, r.XML(verrs))
		}).Respond(c)
	}
	return responder.Wants("html", func(c buffalo.Context) error {
		c.Flash().Add("success", T.Translate(c, "activity.updated.success"))
		return c.Redirect(http.StatusSeeOther, "/activities/%v", activity.ID)
	}).Wants("json", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.JSON(activity))
	}).Wants("xml", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.XML(activity))
	}).Respond(c)
}
func ( v ActivitiesResource ) Update ( c buffalo . Context ) error { tx , ok := c . Value ( " " ) . ( * pop . Connection ) if ! ok { return fmt . Errorf ( " " ) } activity := & models . Activity { } if err := v . scope ( c ) . Find ( activity , c . Param ( " " ) ) ; err != nil { return c . Error ( http . StatusNotFound , err ) } if err := c . Bind ( activity ) ; err != nil { return err } verrs , err := tx . ValidateAndUpdate ( activity ) if err != nil { return err } if verrs . HasAny ( ) { return responder . Wants ( " " , func ( c buffalo . Context ) error { c . Set ( " " , verrs ) c . Set ( " " , activity ) return c . Render ( http . StatusUnprocessableEntity , r . HTML ( " " ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusUnprocessableEntity , r . JSON ( verrs ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusUnprocessableEntity , r . XML ( verrs ) ) } ) . Respond ( c ) } return responder . Wants ( " " , func ( c buffalo . Context ) error { c . Flash ( ) . Add ( " " , T . Translate ( c , " " ) ) return c . Redirect ( http . StatusSeeOther , " " , activity . ID ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . JSON ( activity ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . XML ( activity ) ) } ) . Respond ( c ) }
Update changes a Activity in the DB.
Update changes a Activity in the DB .
// Get the DB connection from the context // Allocate an empty Activity // Bind Activity to the html form elements // 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 show page