redirect uses redirectParams

This commit is contained in:
Michael Snoyman 2010-06-30 21:19:24 +03:00
parent 0652fae94f
commit 5bed76f067

View File

@ -255,16 +255,15 @@ safeEh er = YesodApp $ \_ _ _ -> do
-- | Redirect to the given route. -- | Redirect to the given route.
redirect :: RedirectType -> Routes master -> GHandler sub master a redirect :: RedirectType -> Routes master -> GHandler sub master a
redirect rt url = do redirect rt url = redirectParams rt url []
r <- getUrlRender
redirectString rt $ r url
-- | Redirects to the given route with the associated query-string parameters. -- | Redirects to the given route with the associated query-string parameters.
redirectParams :: RedirectType -> Routes master -> [(String, String)] redirectParams :: RedirectType -> Routes master -> [(String, String)]
-> GHandler sub master a -> GHandler sub master a
redirectParams rt url params = do redirectParams rt url params = do
r <- getUrlRender r <- getUrlRender
redirectString rt $ r url ++ '?' : encodeUrlPairs params redirectString rt $ r url ++
if null params then "" else '?' : encodeUrlPairs params
where where
encodeUrlPairs = intercalate "&" . map encodeUrlPair encodeUrlPairs = intercalate "&" . map encodeUrlPair
encodeUrlPair (x, []) = escape x encodeUrlPair (x, []) = escape x