我正在尝试完成 ihp 博客教程,但我不确定如何解决此错误。我是哈斯克尔的新手。我试过问聊天 gpt,但到目前为止没有运气。
创建帖子时是否需要初始化空评论?我假设是因为 NewView 是用那个字段定义的。
Web/Controller/Posts.hs:47:37
* Fields of `NewView' not initialised:
comment :: Comment
* In the first argument of `render', namely `NewView {..}'
In the expression: render NewView {..}
In a case alternative: Left post -> render NewView {..}
|
47 | Left post -> render NewView { .. }
| ^^^^^^^^^^^^^^
-- Web/Controller/Posts.hs
action CreatePostAction = do
let post = newRecord @Post
post
|> buildPost
|> ifValid \case
Left post -> render NewView { .. }
Right post -> do
post <- post |> createRecord
setSuccessMessage "Post created"
redirectTo PostsAction
-- ./Web/View/Comments/New.hs
data NewView = NewView
{ comment :: Comment
, post :: Post
}
我在帖子的 NewView 中添加了评论字段。那是个错误。删除该字段固定的东西:
diff --git a/Web/View/Posts/New.hs b/Web/View/Posts/New.hs
index 79b073f..9cd06d0 100644
--- a/Web/View/Posts/New.hs
+++ b/Web/View/Posts/New.hs
@@ -3,8 +3,7 @@ import Web.View.Prelude
import qualified Text.MMark as MMark
data NewView = NewView
- { comment :: Comment
- , post :: Post
+ { post :: Post
}
instance View NewView where