Skip to content

Instantly share code, notes, and snippets.

@oleander
Created March 21, 2015 16:12
Show Gist options
  • Save oleander/b63c88b9ddd5275e404e to your computer and use it in GitHub Desktop.
Save oleander/b63c88b9ddd5275e404e to your computer and use it in GitHub Desktop.
Handler/Comment.hs:25:29:
Couldn't match type `Text' with `Entity Post'
Expected type: Field (HandlerT App IO) (Entity Post)
Actual type: Field (HandlerT App IO) Text
In the first argument of `areq', namely `textField'
In the second argument of `(<$>)', namely
`areq textField "Post" (Just post)'
In the second argument of `(<*>)', namely
`(entityKey <$> areq textField "Post" (Just post))'
Handler/Comment.hs:25:52:
Couldn't match expected type `Entity Post' with actual type `Post'
In the first argument of `Just', namely `post'
In the third argument of `areq', namely `(Just post)'
In the second argument of `(<$>)', namely
`areq textField "Post" (Just post)'
module Handler.Comment where
import Import
import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic App
-- POST /posts/comments/:post_id
postCommentR :: PostId -> Handler Html
postCommentR postId = do
post <- runDB $ get404 postId
((res, commentWidget),enctype) <- runFormPost $ entryForm post
case res of
FormSuccess comment -> do
runDB $ insert comment
setMessage $ toHtml $ "Comment created"
redirect $ PostIDR postId
_ -> defaultLayout $ do
setTitle "Please correct your entry form"
$(widgetFile "commentAddError")
-- Applicative Functor
entryForm :: Post -> Form Comment
entryForm post = renderDivs $ Comment
<$> areq nicHtmlField "Body" Nothing
<*> (entityKey <$> areq textField "Post" (Just post))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment