在同一个处理程序yesod中呈现多个表单

时间:2015-04-03 17:35:01

标签: haskell yesod yesod-forms

我想在同一个处理程序中渲染2个不同的表单,但我不确定是否可能。

表格是:

questionForm ::  ExamId -> AForm Handler Question 
questionForm  eid =  Question 
            <$> areq textField (bfs (MsgQuestion)) Nothing 
            <*> pure eid 

answerQuestionForm :: QuestionId -> AForm Handler UserAnswer
answerQuestionForm  qid  = UserAnswer 
            <$> areq textField (bfs (MsgAnswer)) Nothing
            <*> pure Nothing 
            <*> pure qid

我打算使用这个GET方法

 getAnswerQuestionR :: ExamId -> Handler Html
 getAnswerQuestionR eid = do
                mid <- maybeAuthId
                questions <- runDB $ selectList [] [Desc     QuestionQuestionText]
                (articleWidget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ questionForm eid 
                defaultLayout $ do       
                 $(widgetFile "TakeExam/answerQuestion")


 getAnswerQuestionPR :: QuestionId -> Handler Html
 getAnswerQuestionPR qid = do 
           uid <- requireAuthId
           (widget, encoding) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ answerQuestionForm qid
           defaultLayout $ do  
                let  actionR = ExamR                        
                $(widgetFile "TakeExam/answerQuestion")

但此选项不起作用

1 个答案:

答案 0 :(得分:1)

错误消息引用了哪一行代码?

Handler/TakeExam.hs:32:23: 
Not in scope: ‘questions’ In the splice: $(widgetFile "TakeExam/answerQuestion") 

我猜这是第二个处理程序(getAnswerQuestionPR)中的拼接。实际上,在文件拼接的位置,没有名称为questions的标识符可见。