标签: yesod

Yesod持续的例子

我正在和Yesod一起徘徊,我遇到了麻烦,我需要一个很好的例子来说明如何提交表单并将其输入SQLite持久数据库.该耶索德书中谈到了很多关于如何设置一个表,但是很短就如何插入一行的例子,以及如何在数据库中保存的数据的列表.

sqlite haskell web-services yesod

5
推荐指数
1
解决办法
1413
查看次数

在hamlet模板中使用$ forall的麻烦

我和哈姆雷特有一个奇怪的问题.我正在尝试使用$ forall迭代列表,但我不断收到"不在范围内"错误.我在Win7上运行yesod 0.9.2.2.

抛开可怕的设计,任何人都知道我哪里出错了?删除"db"的变量插值可以使执行正常.

相关的小村庄:

 !!!
<h1> Database List
<hr>
<table>

  <tr>
       <td> Host
       <td> Status
  $forall db <- dbList
  <tr>
       <td> #{host db}
Run Code Online (Sandbox Code Playgroud)

相关的处理程序代码:

data Database = Database {dbType :: DBType,
                        host :: String,
                        user :: String,
                        password :: String
                       }


dbList = [Database Oracle "cpalmerws" "system" "***",
          Database Oracle "bdblnx" "system" "***",
          Database Postgres "localhost" "postgres" "***"]

getDBStatusR :: Handler RepHtml
getDBStatusR = do
  mu <- maybeAuth
  defaultLayout $ do
    setTitle "DB Status Page"
    addWidget $(widgetFile "dbstatus")
Run Code Online (Sandbox Code Playgroud)

运行yesod …

haskell yesod hamlet

5
推荐指数
1
解决办法
849
查看次数

我可以在输入表单中有一个文件字段吗?

我需要能够自动将文件和一些相关数据上传到我的Yesod服务器.我认为最好的方法是使用输入表单.

但是,输入表单似乎不允许文件字段.

  1. 我是否正确或有没有办法在输入表单中使用fileAFormReq?
  2. 如果没有这样的方式,那么最好的策略是什么(也就是说如何允许服务器接受来自不同机器的脚本发送的文件,而不需要在任何时候显示表单) ?

谢谢,

forms haskell yesod

5
推荐指数
1
解决办法
276
查看次数

了解Yesod Persistent TH生成的代码

我花了一些时间试图理解模板haskell生成的代码,在这个例子中取自Yesod书:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
    name String
    age Int
    deriving Show
Car
    color String
    make String
    model String
    deriving Show
|]
Run Code Online (Sandbox Code Playgroud)

我觉得我经常看到发生了什么(很多类型编组),但有一节仍然让我感到困惑:

instance PersistEntity (PersonGeneric backend) where
  data instance Unique (PersonGeneric backend) =
  data instance EntityField (PersonGeneric backend) typ
      = typ ~ KeyBackend backend (PersonGeneric backend) => PersonId |
        typ ~ String => PersonName |
        typ ~ Int => PersonAge
  type instance PersistEntityBackend (PersonGeneric backend) =
      backend
Run Code Online (Sandbox Code Playgroud)

数据实例instance EntityField (PersonGeneric backend) typ有三个数据构造函数,这是有意义的(数据库中的每一列都有一个),但即使在查找了代号在haskell中的作用之后,我也无法理解它在那里做了什么.=>通常用于通用量化的原因通常用于似乎没有任何类型的东西?

如果我能以某种方式更清楚,请告诉我.

haskell persistent yesod

5
推荐指数
1
解决办法
214
查看次数

cabal安装挂起安装yesod-platform

yesod-platform的cabal安装挂起下载xss-sanitize.NetHogs没有显示与此下载相关的网络活动.

$ cabal install yesod-platform
Resolving dependencies...
Downloading xss-sanitize-0.3.4...
Run Code Online (Sandbox Code Playgroud)

其他软件包立即下载并安装.

我在Fedora 18上.haskell平台和cabal-install是最新的回购.

$ cabal --version
cabal-install version 0.14.0
using version 1.14.0 of the Cabal library

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1
Run Code Online (Sandbox Code Playgroud)

编辑

我让它一夜之间运行它似乎放弃了xss-sanitizer,并继续安装其他依赖项.这是尾巴.

...
Configuring yesod-test-1.2.1...
Building yesod-test-1.2.1...
Preprocessing library yesod-test-1.2.1...
[1 of 3] Compiling Yesod.Test.CssQuery ( Yesod/Test/CssQuery.hs, dist/build/Yesod/Test/CssQuery.o )
[2 of 3] Compiling Yesod.Test.TransversingCSS ( Yesod/Test/TransversingCSS.hs, dist/build/Yesod/Test/TransversingCSS.o )
[3 of 3] Compiling Yesod.Test       ( Yesod/Test.hs, dist/build/Yesod/Test.o )

Yesod/Test.hs:113:1:
    Warning: In the use of `runFakeHandler' …
Run Code Online (Sandbox Code Playgroud)

haskell cabal-install yesod

5
推荐指数
1
解决办法
506
查看次数

yesod如何显示PersistInt64键的纯值

Dog
    name Text
    race Text

getAllDogsR :: Handler Html
getAllDogsR = do
    Dogs<- runDB $ selectList [] [Asc DogName]
    defaultLayout
        [whamlet|
            <ul>
                $forall Entity dogid dog <- Dogs
                    <li>
                        #{show $ unKey (dogid)}
       |]
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我将获得我的数据库中所有狗键的列表,
如下所示:

  • PersistInt64 1
  • PersistInt64 2
  • PersistInt64 3
  • PersistInt64 4
  • 等等

但我真正想要的是显示密钥的纯值,
如下所示:

  • 1
  • 2
  • 3
  • 4
  • 等等

我的问题是如何实现这一目标.

haskell key persist yesod

5
推荐指数
1
解决办法
505
查看次数

如何快速编译几个Yesod项目?

据我所知,使新的项目yosogyosog2我做了以下

$ yesod init
$ cd yosog
yosog$ cabal sandbox init
yosog$ cabal install

$ yesod init
$ cd yosog2
yosog2$ cabal sandbox init
yosog2$ cabal install
Run Code Online (Sandbox Code Playgroud)

但每一个都cabal install需要永远.如果每个项目都需要永久编译,我怎么想制作一堆Yesod项目呢?

haskell cabal yesod

5
推荐指数
1
解决办法
216
查看次数

Yesod - 在网站上创建用户的最佳方式?

我正在尝试开发一个网站,用户将直接在其上注册,而不是通过Google邮件等进行身份验证.除了通常的用户名/密码,我需要从用户收集更多数据 - 名称,地址等.添加所需功能的最快方法是什么?如果没有编写我自己的Auth插件,我会看到两个选项:

  1. 创建我自己的注册表单(我有点需要做)并使用HashDB存储密码和以后的身份验证.但是,yesod.auth.hashdb似乎已从最新版本中消失了(为什么?)并且只能在这里单独提供:https://github.com/ollieh/yesod-auth-bcrypt/.这有什么不对吗?安全漏洞?

  2. 使用http://hackage.haskell.org/package/yesod-auth-account - 看起来更接近我需要的东西,因为它已经提供了注册页面,但似乎最近的yesod 1.2.5不支持它目前尚不清楚如何将我的其他字段集成到现有的注册过程中

authentication haskell yesod

5
推荐指数
0
解决办法
376
查看次数

Yesod:在ghci中运行`runDB`函数时输入实例错误

在ghci中加载scaffolded站点后获取runDB的正确实例是什么?例如,在运行这句话时:

runDB $ selectList [UserName ==. "Renny"] []
Run Code Online (Sandbox Code Playgroud)

错误是:

Couldn't match type `PersistMonadBackend
(YesodPersistBackend site0 (HandlerT site0 IO))'
with `persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend'
The type variable `site0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: PersistMonadBackend
                 (YesodPersistBackend site0 (HandlerT site0 IO))
  Actual type: PersistEntityBackend User
In the second argument of `($)', namely
  `selectList [UserName ==. "Renny"] []'
In the expression: runDB $ selectList [UserName ==. "Renny"] []
In an equation for `it':
    it = runDB $ …
Run Code Online (Sandbox Code Playgroud)

haskell persistent ghci yesod

5
推荐指数
1
解决办法
449
查看次数

如何在Yesod中导入莎士比亚模板?

我在Yesod中使用QuasiQuotations,并且一切正常。但是我的文件变得很大,看起来也不好看。另外,我的TextEditor不能正确突出显示此语法。这就是为什么这样分割我的文件:

getHomeR :: Handler Html
getHomeR = do
    webSockets chatApp
    defaultLayout $ do
        $(luciusFile "templates/chat.lucius")
        $(juliusFile "templates/chat.julius")
        $(hamletFile "templates/chat.hamlet")
Run Code Online (Sandbox Code Playgroud)

如果这是错误的,请告诉。这样做runghc myFile.hs会引发许多错误,例如:

chat_new.hs:115:9:
    Couldn't match expected type ‘t0 -> Css’
                with actual type ‘WidgetT App IO a0’
    The lambda expression ‘\ _render_ajFK
                             -> (shakespeare-2.0.7:Text.Css.CssNoWhitespace . (foldr ($) ...))
                                  ...’
    has one argument,
    but its type ‘WidgetT App IO a0’ has none
    In a stmt of a 'do' block:
      \ _render_ajFK
      ...
Run Code Online (Sandbox Code Playgroud)

和这个。

chat_new.hs:116:9:
    Couldn't match type ‘(url0 -> [(Text, …
Run Code Online (Sandbox Code Playgroud)

templates haskell ghc yesod hamlet

5
推荐指数
1
解决办法
133
查看次数