McBear Holden
McBear Holden

Reputation: 5901

Yesod Hamlet getHomeR can't find reference

getHomeR :: Handler Html
getHomeR = do
    wordList <- runDB $ selectList [] [] :: HandlerT App IO [Entity Vocabulary]
    defaultLayout
        [whamlet|
            <ul>
                $forall Entity wordid wordItem <- wordList
                    <li>
                        <a href=@{HomeR}>#{date wordItem}
        |]

I get this error

Variable not in scope: date :: Vocabulary -> a0

while I have defined in models:

Vocabulary json
    word Text
    date UTCTime
    deriving Show

PS: I'm developing based on the yesod scaffold example: yesod-postgres

Upvotes: 0

Views: 73

Answers (1)

mb14
mb14

Reputation: 22596

It should be vocabularyDate instead of just date. According to the persistent section on the yesod book,

mkPersist sqlSettings [persistLowerCase|
Person
    name String
    age Int
    deriving Show
|]

will generates code which looks like

data Person = Person
    { personName :: !String
    , personAge :: !Int
    }
  deriving Show
 ...

As you can see, the field names are prefixed by the data name (personName instead of name). This is a standard practice in Haskell to avoid name collision.

Upvotes: 2

Related Questions