I'm not sure what have you already tried, but since this is practically a join (and persistent's type-safe API doesn't support them), running a custom SQL query should be the most efficient solution. If your model looks something like this EntityA key Text value Text deriving Show EntityB foreignKey EntityAId...
It's been a while since I worked on the code, so don't take this as authoratative (like Daniel mentioned, -ddump-simpl is a good call here). But I don't believe we're using the blaze-html combinators, just the data type. Hamlet itself concatenates strings as much as possible at compile time to...
You can find an example in the test/YesodCoreTest/Redirect.hs file available in the current Yesod 1.4.9.1 archive: import qualified Network.HTTP.Types as H myR :: Handler Html myR = redirectWith H.status301 HomeR For a list of available response codes, see the Network.HTTP.Types documentation....
So, I'd probably advise moving your counter ID into the URL, so you're doing something like POSTing to /counters/1/increment or something. Feels slightly off to have the ID in a hidden field. However, if you did want to keep it in a hidden field, you can have the form take...
You can use runRequestBody to get direct access to all of the POST parameters and files.
It turns out this was a bug in the cartridge and is fixed now.
You can use cached and cachedBy for per-request caching.
In the Haskell language report exporting a module is described as: The form “module M” names the set of all entities that are in scope with both an unqualified name “e” and a qualified name “M.e”. This set may be empty. §5.2 Export Lists An export list identifies the entities...
No, there's no way to do that. The yesod code runs server side, and the JavaScript client side. The only way to achieve that kind if thing is to have the JavaScript send values back to the server.
Using global constants is trivial in Haskell: you just write foo = bla somewhere (preferrably with a signature foo :: FooType). foo can then be used anywhere in your module (or even outside, if you export it). Global variables OTOH aren't really possible in Haskell, as such. For the most...
You can just include it like any other tags. Don't put spaces before and after equals sign. <svg height="50" width="500">...
haskell,yesod,template-haskell
EDIT: Simple type signature parameterization example added I think there is a problem with function name binding in your mkDeleteHandler. I would try something like this for example (example simplified): mkHandler :: String -> String -> Q [Dec] mkHandler typeName funcName = do funDecl <- [d| funcName :: String ->...
No, such syntax does not exist.
haskell,yesod,shakespeare-text
For this you use sendFile in your handler function (see its definition) The first argument is the Mime Type while the second is the file path. For example, you could code something like: getMyFileR :: Handler () getMyFileR = sendFile "text/html" "myfile.html" Here’s Another example. Say I have the following...
If you're using the Yesod scaffolding, the handler and db functions are provided to let you run handler actions and database queries, respectively, from the repl: $ cabal repl db $ selectList [UserName ==. "foo"] [] Edit: I've also updated Yesod's wiki page on GHCi with this information. It includes...
As you probably already know, one of Haskell's strengths is strong typing. The persistent-sqlite package takes this to an extreme (which, in my opinion, is a good thing) by requiring that table entries have their own data type. For instance, if you have a table which holds fruits that looks...
In the newest versions of the scaffolding, we no longer have the concept of environments. Command line arguments can be used to switch which config files we read from, but that's it. If you'd like access to that information, you could use getArgs.
This is what I do: postSomethingR = do ((res, _), _) <- runFormPost form case res of FormSuccess (account, file) -> do bytes <- runResourceT $ fileSource file $$ sinkLbs -- Parse the ByteString in another thread parseHandler <- handlerToIO liftIO $ forkIO $ parseHandler $ do case CSV.parseCSV csvSettings...
haskell,yesod,template-haskell
I haven't actually used the composite primary key feature myself, but this error makes sense to me. There's not obvious serialization to Text for arbitrary composite keys, and so persistent doesn't generate it for you. If you'd like to use a MovieId inside your URLs, you'll need to manually define...
You can use (a) and (b) behind a proxy (c) -- NGINX is my personal preferred server for that purpose because it is insanely fast and good on resources. http://nginx.org/en/docs/beginners_guide.html#proxy You'd do something like this: server { location / { proxy_pass http://localhost:{port for a}/; } location /wp { proxy_pass http://localhost:{port...
You need to add the following constraint to the postDemoNewR declaration: YesodPersist master => YesodPersistBackend master ~ SqlBackend => … The first constraint tells master must have persistent abilities while the second constraint tells the backend used for persistent should be an SQL backend. You can find something similar in...
I'm assuming based on the question that you're using the standard scaffolding. If you look in the code, you'll find that uses loadAppSettingsArgs, which is described as: Same as loadAppSettings, but get the list of runtime config files from the command line arguments. If you don't want to pay attention...
The function you're looking for is runRequestBody: http://www.stackage.org/haddock/lts-2.7/yesod-core-1.4.9.1/Yesod-Core-Handler.html#v:runRequestBody
ms's comment is correct: you should put FooR before StaticR. In addition, you'll need to turn off overlap checking. The easiest way is probably to use parseRoutesFileNoCheck instead of parseRoutesFile (or parseRoutesNoCheck instead of parseRoutes if you're using the quasiquoter).
postgresql,migration,yesod,persistent
Persistent does not currently have any built-in support for triggers, though it's something we've been wanting to add (simply lacking manpower). For now, you'll have to add the trigger manually.
There are many approaches to this, mostly depending on what flavor of devops/hosting your prefer. One option is to put a dummy value in the config file and override it with an environment variable at runtime (see: https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables). You can also having an extra settings file for production that overrides...
It looks like you originally wrote the code using Persistent 2, and are now using Persistent 1.3. On 1.3, you'd need something like type YesodPersistBackend App = SqlPersistT.
There's a Wiki page covering the syntax. The Gt and Desc is an old syntax that's no longer needed, I'll remove the references from the chapter (I thought I'd caught them all already).
You need to use runDB around your persistent call.
When working with monad transformers, to convert from some monad m to a transformer t m, you have to use the lift function: lift :: (MonadTrans t, Monad m) => m a -> t m a This is actually the defining method of the MonadTrans typeclass, so the implementation is...
I got it. I was not clear of what "tableMform extra" has to return. I know that it has to return something of type [(FormResult a, xml)][1] . But then I was not sure what the type of "forM lis ((w,h) -> mopt intField (fromString w) (Just h) )" --...
Because it generally confuses people when they can't run yesod directly; installing the executables into ~/.cabal/bin means that the user can always access them. It does leak some information outside of the sandbox, but it's typically the right trade-off to take.
I presume you're using something like areq (radioField ...) "Some Name" Nothing right now. That Nothing value means "no default." To provide a default, replace it with (Just someDefault).
What does the syntax <$> and <*> mean respectively? pure and <*> are two class methods of type class Applicative, <$> is an infix synonym for fmap, which is one of the class methods of Functor. Chatper 11 Functors, Applicative Functors and Monoids of Learn You a Haskell has...
haskell,markdown,interpolation,yesod
Well, finally I've found really simple solution. Any quasi quoter could be easily switched to file input rather than inline text with quoteFile function from Language.Haskell.TH.Quote module1. Let's describe in Foundation module following function: import Language.Haskell.TH.Quote (QuasiQuoter, quoteFile) import Text.Shakespeare.Text (st) stFile :: QuasiQuoter stFile = quoteFile st Now we...
Have a look in your browser console, most likely you're getting 404s due to bad relative links. I'd try using a redirect call to point to the static for so that all of the relative links are correct.
haskell,yesod,template-haskell,hamlet
Import Yesod.Core and Yesod.Core.Widget, they will provide the appropriate functions. Also note that they have a online version of the book. And generally if you see import errors, do a search on Hoogle and in most of the cases you are likely to find a solution there....
Hamlet is just providing an alternate syntax for normal Haskell code, so like normal Haskell, you have to keep your impure actions separate. In other words, you need to run the IO action outside of the template.
Take a look at the types for insert and replace (ignoring the constraints for brevity): insert :: val -> m (Key val) replace :: Key val -> val -> m () Branches of a case expression have to have the same type. (Otherwise sck's type would be different depending on...
Since you are running monad actions at the end of your case, you don't need to return the case. isAdmin = do mu <- maybeAuthId case mu of Just "Foo" -> Authorized Just _ -> Unauthorized "You are NOT a Admin !" Nothing -> do setMessage "You have to Login...
I' wasn't sure about the SelectOpts only being applicable to entity value, so I checked that in a small snippet of code. Assuming an entity looks like this: EntityA key Text time UTCTime deriving Show you can just list SelectOpts you're interested in and get the desirable output. The sample...
templates,comments,yesod,shakespeare-text,julius
If you're asking specifically about Julius templates, the answer is that there isn't any built-in commenting syntax, and therefore the only option is JavaScript style comments. However, as you've mentioned, this can conflict with the CPP language extension. One option to work around this is to put the template in...
Probably you are trying to run old code that does not work with current Yesod. You can get this to compile and run (ghc-7.10.1, yesod-1.4.1.5) with import Data.Enumerator (run_) ... bss <- run_ consume but I'm not sure what you want it to do. As is, it will return an...
haskell,monads,yesod,persistent
I think you need to replace: let contacts = map (\(Entity key val) -> (get $ ((contactContact val) :: UserId) )) contacts' with: contacts <- mapM (\(Entity key val) -> (get $ ((contactContact val) :: UserId) )) contacts' (Yes, the Persistent error messages here are terrible, we're working on that...
The token is stored in the user session. You can get access to it via: fmap reqToken getRequest ...
You need to add liftIO in front of atomically, to lift the IO action into the Persistent monad.
Try giving sortOrder' a type signature. where sortOrder' :: EntityField Model typ -> SelectOpt Model sortOrder' = case sortOrder of "Asc" -> Asc "Desc" -> Desc This compiles using GHC 7.6.2....
In order to do that, you'll need to use the StaticRoute constructor directly. The identifier generation only generates identifiers for files, not directories, since that's normally what people want (as @zudov explains). You should be able to do something like: @{StaticR $ StaticRoute ["images"] []} ...
object is not in scope in prelude. Which package/module defines this? Yesod.Json Why doesn't it take the key-value pair in the above case? It takes the key value pair just fine. The error message is telling you that object gives you a Value, but you declared getHome to be...
You can use multi-piece routes, and will likely need overlap checking turned off. This would look like: !/*Texts HomeR GET For more information, see the routing chapter of the Yesod book....
myApp has this type: myApp :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived so you can add your own IO action before returning the response like this: myApp _ respond = do putStrLn "processing request" respond $ responseLBS status200 [("Content-Type", "text/plain")] "Hello World" ...
I wouldn't go this route, specifically because of the type inference issue you already discovered. Explicitly having to call toWidget occasionally is probably the best compromise here.
Does /opt/cabal/1.20/bin contain version 1.20 of cabal? If so, put that directory in front of your PATH - i.e. replace the export PATH= in your .bashrc with: export PATH="/opt/cabal/1.20/bin:~/.cabal/bin:/opt/ghc/7.8.3/bin:$PATH" Reload your .bashrc and see what cabal sandbox --help reports....
haskell,module,hierarchy,yesod
You are correct, but that point is also addressed in the yesod book. For example have a look at http://www.yesodweb.com/book/scaffolding-and-the-site-template, the section called "Foundation and Application modules". Usually you have a Foundation module that defines route types and handler functions, and an Application module that defines the dispatching. So all...
haskell,yesod,persistent,esqueleto
Thanks to @JPMoresmau's hinting, I ended up with a much shorter, and I think simpler approach. It may be slower on large datasets due to nub, but on small datasets it returns far faster than I need it to. I still hate that I have so much manual plumbing to...
mysql,database,haskell,yesod,persistent
You're almost there. You just need to use one of the functions from monad-logger to provide a MonadLogger context. You may want to try runStdoutLoggingT.
The instructions in this quick start guide led you to create a sandbox for your project, thus the dependencies you installed are only available within this sandbox (which is the cautious and arguably correct way to do it, avoiding collisions and easing the cleanup). GHCi is part of GHC and...
This is just a case where I forgot to expose the identifiers. Version 1.2.14 of yesod-core includes these two functions.
The from table parameters types are sometimes deduced from the result type which must be explicit. Other ambiguities arise about the monad type usually. It is useful to enclose the query in a specific function to solve some ambiguities. I cannot certify your esqueleto query conformity now but Try this:...
You can see here the relevant code: backendBS :: Backend -> S.ByteString backendBS Sqlite = $(embedFile "hsfiles/sqlite.hsfiles") backendBS Postgresql = $(embedFile "hsfiles/postgres.hsfiles") backendBS PostgresqlFay = $(embedFile "hsfiles/postgres-fay.hsfiles") backendBS Mysql = $(embedFile "hsfiles/mysql.hsfiles") backendBS MongoDB = $(embedFile "hsfiles/mongo.hsfiles") backendBS Simple = $(embedFile "hsfiles/simple.hsfiles") backendBS Minimal = $(embedFile "hsfiles/minimal.hsfiles") So, it's used...
haskell,configuration,yesod,typeclass
I'm going to simplify the problem so that we only need core libraries. We want to change how we Show a MarkdownText based on some ExampleSettings that contain a prefix and a suffix. {-# LANGUAGE OverloadedStrings #-} import Data.Text as T import Data.Monoid import Data.String newtype MarkdownText = MarkdownText {...
A PersistField isn't the same as a Field. You want to make a custom field by importing Yesod.Forms. Here's an example, for a MathJax type ;) newtype MathJax = MathJax { unMathJax :: Markdown } deriving (Eq, Ord, Show, Read, PersistField, PersistFieldSql, IsString, Monoid) unMM :: MathJax -> Text unMM...
1 - Double example - set default value at field and for whole personeForm: data Person = Person { name :: Text , age :: Maybe Int } personeForm :: Maybe Person -> AForm Handler Person personeForm person = Person <$> areq textField "Persone Name" (name <$> person) <*> aopt...
Here's an implementation of roughly what Rails is doing. This involves several parts: generating the link, using Javascript to implement the method changing functionality, and extra code for CSRF protection on the backend. Here's the linking aspect: linkToPost :: Route App -> [(Text,Text)] -> Text -> Widget linkToPost = linkToMethod...
html,css,twitter-bootstrap,yesod
I got it. It was simple. The change was to be made to the input tag. So I added the following to my lucius file input { width:3em; } which was allowing me to control the width. ...
The putStrLn from ClassyPrelude takes a Text, not a String. The simplest solution would be to change the Renderer import to the Text version of the module.
Have you taken a look at the regex-tdfa-text package? It provides backend support for using the regex-base library with Text strings.
you have to add an type that is an instance of PathMultiPiece after the * like this: /*Texts HomeR GET (Texts, which is just a synonym for [Text] is an instance because Text is an instance of PathPiece) and of course you have to add it as an argument to...
haskell,yesod,cabal-install,nixos
I was able to get this working after using the method on O'Charles' Nix wiki. I have not determined why this method was not working before. Basically, first run cabal2nix. Then create a generic shell.nix (that can be shared between all Haskell packages). $ cabal2nix --jailbreak --sha256=X ./$cabal > default.nix...
haskell,yesod,script-tag,yesod-forms
Where scripts get placed will depend on jsLoader. If you want to make a change for a specific script, you can use toWidgetHead [hamlet|<script src=...">|].
Hoogle on stackage.org is a great resource for these kinds of questions: http://www.stackage.org/lts/hoogle?q=pageBody...
Why did cabal fail to create a yesod binary? How do I fix this install? The yesod binary isn't part of the yesod package anymore. Instead, it has been extracted into the yesod-bin package: cabal install yesod-bin The binary should be in ~/Library/Haskell/bin, however, I'm not an OSX user....
Not directly the way you are describing. You can have onclick use some Javascript to make an AJAX call, which will trigger a handler function to be run.
haskell,yesod,typeclass,persistent,monad-transformers
Turns out I didn't realize you needed to repeat constraints inside of functions as well. This worked: _ <- rawSql "SELECT ?? FROM my_entities WHERE id = ? FOR UPDATE" [toPersistValue somethingId] :: MonadIO m => SqlPersistT m [Entity MyEntity] ...
This query works. The difference between the query I had posted in my question and this one is really the ?. I thought I tried that variation but perhaps missed the obvious. I am still unclear when we will use ?. though. . I noticed I also get a working...