yesod

what does “Not a PersistText value” mean?

半城伤御伤魂 提交于 2020-01-06 02:11:11
问题 I'm new to yesod and I'm trying to make the same blog project from this screencast: https://www.youtube.com/watch?v=SadfV-qbVg8 with the only difference being that I'm using MariaDB instead of PostgreSQL. Every time I add a new blog post and redirect to the page that shows it I see this error: [Error#yesod-core] get BlogPostKey {unBlogPostKey = SqlBackendKey {unSqlBackendKey = 5}}: field article: Not a PersistText value @(yesod-core-1.4.12:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs

what does “Not a PersistText value” mean?

折月煮酒 提交于 2020-01-06 02:10:23
问题 I'm new to yesod and I'm trying to make the same blog project from this screencast: https://www.youtube.com/watch?v=SadfV-qbVg8 with the only difference being that I'm using MariaDB instead of PostgreSQL. Every time I add a new blog post and redirect to the page that shows it I see this error: [Error#yesod-core] get BlogPostKey {unBlogPostKey = SqlBackendKey {unSqlBackendKey = 5}}: field article: Not a PersistText value @(yesod-core-1.4.12:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs

How to run bash commands like “npm install” on complie

痞子三分冷 提交于 2020-01-04 09:28:22
问题 I need to run npm install && gulp build inside my static/semantic-ui folder, so it creates the needed css file. I saw this example with Setup.hs, however on my scaffolded project I don't have it, so my question where is the right place to put the code to run those bash commands. 回答1: If you're using the default Yesod scaffolding (generated by stack tool), then it indeed doesn't contain Setup.hs (which is a bit weird, as their own guide - https://github.com/commercialhaskell/stack/blob/master

Render url with query parameters

我只是一个虾纸丫 提交于 2020-01-04 04:44:09
问题 Can't find solution to a simple problem, the answer should be obvious. How to render url with a query parameters inside hamlet template? I.e. @{ItemsR} will generate http://localhost:3000/items and how do I generate something like http://localhost:3000/items?page=10&sort=name ? 回答1: Yesod is RESTful, you should use arguments in url format (eg. /items/page/10/sortby/name ) if you wish use QueryString format then, you loss the Yesod type safe url management. Below example show how use different

multiSelectField with pre-selected options in Yesod

扶醉桌前 提交于 2020-01-04 04:40:27
问题 I have a many-to-many relationship between two entities. For example, let's think about a blogpost which can have multiple authors. This could be a simple model for it: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| Person name String age Int Maybe deriving Show Blogpost title String deriving Show PersonBlogpost person PersonId blogpost BlogpostId |] My idea is to have an "Edit" page for a Blogpost entity, and in it have a multiSelectField for the authors, and have

How to print comma-separated list with hamlet?

Deadly 提交于 2020-01-03 12:37:15
问题 With the hamlet templating language that comes with yesod, what is the best way of printing a comma-separated list? E.g. assume this code which just prints one entry after another, how do I insert commas in between the elements? Or maybe even add an “and” before the last entry: The values in the list are $ forall entry <- list #{entry} and that is it. Some templating languages such as Template Toolkit provide directives to detect the first or last iteration. 回答1: I don't think there's

How to print comma-separated list with hamlet?

血红的双手。 提交于 2020-01-03 12:35:31
问题 With the hamlet templating language that comes with yesod, what is the best way of printing a comma-separated list? E.g. assume this code which just prints one entry after another, how do I insert commas in between the elements? Or maybe even add an “and” before the last entry: The values in the list are $ forall entry <- list #{entry} and that is it. Some templating languages such as Template Toolkit provide directives to detect the first or last iteration. 回答1: I don't think there's

Displaying dynamically generated images in Yesod

亡梦爱人 提交于 2020-01-01 08:38:21
问题 I'm writing my first Yesod app. The application involves the user selecting to view a graph, dynamically generated based on data stored in a DB on the server. I know how to get the user request and create the image on the server's file system, but how do I create a response page presenting it? P.S. As I'm using GnuPlot to generate the image, I only know how to write it as a file to the file system, but If you happen to know how to get the data in memory it'll probably be even better. Thanks,

Capturing Persistent Relations in a Form

≯℡__Kan透↙ 提交于 2019-12-31 04:43:12
问题 I have defined a one-to-many relationship in Persistent but could not figure out how to create a form that can take one of the foreign keys as input. Simplifying my use case to something like this: Person name String Car personId PersonId name Text type Text Now when I try to generate a Form for Car, what should be the field type for personId? I tried something like this but get an error: entryForm :: Maybe Car -> Form Car entryForm car = renderDivs $ Car <$> areq personIdField "Person"

Allowing cross-origin requests in Yesod

本秂侑毒 提交于 2019-12-30 00:56:08
问题 My application uses a bookmarklet, and I need to allow CORS for MyRouteR so my bookmarklet code can use this route for AJAX requests. In my first draft of config/routes I gave MyRouteR support for only one request method, PUT. But it turned out (duh) that I'd need to support the OPTIONS method as well, which browsers use for CORS preflight requests. I ended up with the following in config/routes: /myroute MyRouteR PUT OPTIONS I was kind of hoping there would be some relevant machinery in the