Yesod持久性函数无法从Handler中访问。我应该包括什么?

时间:2013-09-20 23:14:20

标签: haskell scaffolding yesod include-path persistent

我在略微改变的Yesod脚手架上遇到了麻烦。我在/ config / models中描述了我的实体:

Artist
    ident Int
    value Text

这是我在/Handler/Artist.hs的处理程序

{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell,
             OverloadedStrings, GADTs, FlexibleContexts #-}
module Handler.Artist where

import Import
import qualified Control.Monad.IO.Class as M
import Text.Hamlet (shamlet)
import Text.Blaze.Html.Renderer.String (renderHtml)
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH
import Control.Monad.IO.Class (liftIO)

getArtistR = concatMap (renderListElement . value) $ artists
  where artists = selectList ([] :: [Filter Artist]) []
        renderListElement name = renderHtml [shamlet|<li>#{name}|]

(我包括冗余:))

最后,我的错误:

Rebuilding application... (using cabal)

Handler/Artist.hs:14:45: Not in scope: `value'
Build failure, pausing...

我不知道该怎么做!我是否需要在处理程序中输入$(widgetFile "artist")之类的内容?补丁哪里出错了?任何帮助都会非常棒。提前谢谢!!!

1 个答案:

答案 0 :(得分:1)

您应该为函数添加模型名称前缀,以便value变为artistValue

文档包含example生成的代码。