// Destroy deletes a Widget from the DB. This function is mapped
// to the path DELETE /widgets/{widget_id}
Destroy deletes a Widget from the DB. This function is mapped
to the path DELETE /widgets/{widget_id}
// Destroy deletes a Widget from the DB . This function is mapped // to the path DELETE / widgets / { widget_id }
func (v WidgetsResource) Destroy(c buffalo.Context) error {
	tx, ok := c.Value("tx").(*pop.Connection)
	if !ok {
		return errors.WithStack(errors.New("no transaction found"))
	}
	widget := &models.Widget{}
	if err := tx.Find(widget, c.Param("widget_id")); err != nil {
		return c.Error(404, err)
	}
	if err := tx.Destroy(widget); err != nil {
		return errors.WithStack(err)
	}
	c.Flash().Add("success", "Widget was destroyed successfully")
	return c.Redirect(302, "/widgets")
}
func ( v WidgetsResource ) Destroy ( c buffalo . Context ) error { tx , ok := c . Value ( " " ) . ( * pop . Connection ) if ! ok { return errors . WithStack ( errors . New ( " " ) ) } widget := & models . Widget { } if err := tx . Find ( widget , c . Param ( " " ) ) ; err != nil { return c . Error ( 404 , err ) } if err := tx . Destroy ( widget ) ; err != nil { return errors . WithStack ( err ) } c . Flash ( ) . Add ( " " , " " ) return c . Redirect ( 302 , " " ) }
Destroy deletes a Widget from the DB.
Destroy deletes a Widget from the DB .
// Get the DB connection from the context // Allocate an empty Widget // To find the Widget the parameter widget_id is used. // If there are no errors set a flash message // Redirect to the widgets index page