Turbo/Streams/Controller
// app/controllers/post_controller/postcontroller.go
package postcontroller
import "golazy.dev/lazycontroller"
func (c *PostsController) Create(form *PostForm) error {
post, err := c.posts.Create(form.Title)
if err != nil {
return err
}
c.Set("post", post)
c.Set("form", &PostForm{})
return c.Wants(lazycontroller.Formats{
lazycontroller.HTML: func() error {
return c.RedirectToRoute("post", post.ID)
},
lazycontroller.TurboStream: func() error {
return c.Render("create")
},
})
}