2015-04-03 86 views
2

我想在同一個處理程序中呈現2個不同形式,但我不確定是否可能。在同一個處理程序中呈現多個表單yesod

的形式是:

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") 

但這個選項不能正常工作

+2

究竟是什麼「不工作」?你在編譯時遇到錯誤嗎?在運行時?正確運行哪個命令?什麼輸出? – d8d0d65b3f7cf42 2015-04-03 18:36:13

+0

是的我在編譯時出錯:Handler/TakeExam.hs:32:23: 不在範圍內:'questions' 在splice中:$(widgetFile「TakeExam/answerQuestion」) – oriaj 2015-04-03 22:59:10

回答

1

什麼行代碼執行錯誤消息指什麼?

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

我估計是在所述第二處理器(getAnswerQuestionPR)拼接。事實上,在文件拼接處,沒有名稱爲questions的標識符可見。

相關問題