我有一个Yesod表单,用于编辑一些静态页面的内容,这些页面使用markdown编写(使用Pandoc处理).我想要两个按钮 - 一个"预览"按钮,用于处理标记并在表单下方显示结果,还有一个"提交"按钮,用于将内容保存到数据库中.
使用Yesod执行此操作的最简单方法是什么?Yesod书中的所有表格示例都只有一个按钮.我已经看过暴露的函数/ api,但即使我在表单中添加了多个具有不同名称和/或值的提交按钮,我也无法弄清楚如何让Yesod告诉我哪个被按下了.
任何人都可以给我一个简单的例子,说明在Yesod中有一个以上按钮的表单会触发不同的操作吗?
当我尝试使用命令"cabal install yesod"安装yesod时,我收到以下错误:
cabal install rsa
Resolving dependencies...
Configuring RSA-1.0.6.1...
Preprocessing library RSA-1.0.6.1...
Preprocessing executables for RSA-1.0.6.1...
Building RSA-1.0.6.1...
[1 of 1] Compiling Codec.Crypto.RSA ( Codec/Crypto/RSA.hs, dist/build/Codec/Crypto/RSA.o )
Codec/Crypto/RSA.hs:577:10:
Duplicate instance declarations:
instance Random Word8 -- Defined at Codec/Crypto/RSA.hs:577:10-21
instance Random Word8 -- Defined in System.Random
cabal: Error: some packages failed to install:
Run Code Online (Sandbox Code Playgroud)
似乎RSA lib与另一个库冲突.
任何的想法?
我的环境:Mac OS X 10.7 GHC 7.0.3
提前致谢.
我不知道如何解决这个问题.有人有什么想法吗?
我尝试时收到以下错误消息:
~ >>> cabal install yesod
Resolving dependencies...
Configuring aeson-0.5.0.0...
Preprocessing library aeson-0.5.0.0...
Preprocessing test suites for aeson-0.5.0.0...
Building aeson-0.5.0.0...
[ 1 of 10] Compiling Data.Aeson.Types.Internal ( Data/Aeson/Types/Internal.hs, dist/build/Data/Aeson/Types/Internal.o )
[ 2 of 10] Compiling Data.Aeson.Functions ( Data/Aeson/Functions.hs, dist/build/Data/Aeson/Functions.o )
[ 3 of 10] Compiling Data.Aeson.Types.Class ( Data/Aeson/Types/Class.hs, dist/build/Data/Aeson/Types/Class.o )
[ 4 of 10] Compiling Data.Aeson.Types ( Data/Aeson/Types.hs, dist/build/Data/Aeson/Types.o )
[ 5 of 10] Compiling Data.Aeson.Parser.Internal ( Data/Aeson/Parser/Internal.hs, dist/build/Data/Aeson/Parser/Internal.o )
SpecConstr
Function `$j_sqbP{v} [lid]'
has two call patterns, but …Run Code Online (Sandbox Code Playgroud) Yesod的内置i18n消息文件非常好,但我注意到两个问题:
谢谢你的任何建议!
我正在玩脚手架网站,我希望在用户首次使用OpenID或Google帐户登录后将用户发送到注册页面.
我想出了这个:
getAuthId creds = runDB $ do
x ? getBy $ UniqueUser $ credsIdent creds
case x of
Just (Entity uid _) ? return $ Just uid
Nothing ? do
return $ Just $ Key (PersistInt64 0)
Run Code Online (Sandbox Code Playgroud)
在HomeR处理程序中我检查UserId值,如果为零则显示注册表单.
这种方法有效,但似乎是hackish.处理这种问题的正确方法是什么?
我是Haskell的新手,你也可以向Yesod推测它.我想用两种方法来学习更多关于Haskell和Web开发的方法.
我有两个问题,由于我缺乏Haskell知识,它们都可能是我犯的愚蠢错误:
(1)我用sqlite创建了一个脚手架网站(我使用的是Yesod 1.2).我尝试在生成的homepage.hamlet文件中只添加一行,它给了我一个错误(顺便说一句,没有这个添加,网站工作正常).我添加的行是:
<a href=@{AuthR LoginR}>Go to the login page
Run Code Online (Sandbox Code Playgroud)
之后我收到此错误消息:
Handler/Home.hs:34:11:
Not in scope: data constructor `LoginR'
In the result of the splice:
$(widgetFile "homepage")
To see what the splice expanded to, use -ddump-splices
In a stmt of a 'do' block: $(widgetFile "homepage")
In the second argument of `($)', namely
`do { aDomId <- newIdent;
setTitle "Welcome To Yesod!";
$(widgetFile "homepage") }'
Run Code Online (Sandbox Code Playgroud)
有没有办法在其他处理程序/模板中公开LoginR?
(2)我最终想要自定义登录页面的外观和感觉,所以我试着按照这里的说明(也认为这可能解决了上述问题,因为我在范围内声明了我自己的Handler):http://hackological.com/ blog/using-twitter-to-authenticate-in-yesod /.基本上我修改了Foundation.hs的authRoute语句,如下所示
authRoute _ = Just LoginPanelR
Run Code Online (Sandbox Code Playgroud)
然后添加路线:
/login LoginPanelR …Run Code Online (Sandbox Code Playgroud) 我必须谈谈Yesod(简单).是的,..我从来没有或真的很少使用haskell.大学讲师.....呵呵.
所以我读了一本关于yesod的书,在一些章节中,作者正在使用像<$>和的一些运算符<*>.有人可以用简单的话来解释,这个运营商做了什么?很难谷歌为那些字符和如果试图阅读Control.Applicative的文档,但说实话,它很难得到一个haskell初学者.
所以我希望任何人都有一个简单的答案:)
使用这些运算符的书的示例:
......
personForm :: Html -> MForm Handler (FormResult Person, Widget)
personForm = renderDivs $ Person
<$> areq textField "Name" Nothing
<*> areq (jqueryDayField def
{ jdsChangeYear = True -- give a year dropdown
, jdsYearRange = "1900:-5" -- 1900 till five years ago
}) "Birthday" Nothing
<*> aopt textField "Favorite color" Nothing
<*> areq emailField "Email address" Nothing
<*> aopt urlField "Website" Nothing
data Person = Person
{ personName :: Text
, …Run Code Online (Sandbox Code Playgroud) 这是一个当前失败的"hello world"尝试 - 我只是尝试selectList使用以下代码在SqLite数据库上运行查询:
Database.Persist.Sqlite> runSqlite "database.sqlite" $ selectList [] [LimitTo 10]
<interactive>:46:1:
Couldn't match expected type ‘SqlBackend’
with actual type ‘PersistEntityBackend val0’
The type variable ‘val0’ is ambiguous
In the first argument of ‘print’, namely ‘it’
In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)
这几乎看起来太简单了搞砸......我哪里出错了?
传统上,人们将Web应用程序视为MVC - 它假设是面向对象的上下文.
函数式编程批评了这一点 - 并提供了一个使用高阶函数和不可变数据结构的模型.
我的问题是:你如何解释像Ring和Yesod这样的纯功能网络服务器不是MVC?
model-view-controller haskell functional-programming clojure yesod
尝试运行我的Yesod应用程序时遇到此问题.stack build已经运行并且不再输出任何输出.
$ stack exec -- yesod devel
Executable named yesod not found on path: ["path/to/app"]
Run Code Online (Sandbox Code Playgroud)