Fork me on GitHub
#lambdaisland
<
2020-07-23
>
plexus10:07:53

@orlandomr27 how's your luminus app going? did you get those routes to work?

theequalizer7311:07:57

Hi @plexus, I'm glad you asked. My wiki route is working fine, with some changes. But I could understand how to get :slug from the :path-params . This is my code right now for the lambwiki.routes.home namespace:

(ns lambwiki.routes.home
  (:require
   [lambwiki.layout :as layout]
   [lambwiki.db.core :as db]
   [ :as io]
   [lambwiki.middleware :as middleware]
   [ring.util.response]
   [ring.util.http-response :refer [found]]))

(defn home-page [request]
  (layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))

(defn render-wiki-page [request page]
  (clojure.pprint/pprint page)
  (layout/render request "wiki-page.html" page))

#_(defn about-page [request]
    (layout/render request "about.html"))

(defn home-routes []
  [""
   {:middleware [middleware/wrap-csrf
                 middleware/wrap-formats]
    :conflicting true}
   ["/"      {:get (fn [] (found "/wiki/home"))}]
   ["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
                     (when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
                       (render-wiki-page request page)))}]])
"/wiki:/slug" route is working if I add the handler home-page to "/", but I'm getting an error with "/" when I use found "/wiki/home
user> (start)
Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:19).
path "/" doesn't have a :handler defined for :get

{:path "/", :data {:middleware [#function[lambwiki.middleware/wrap-csrf] #function[lambwiki.middleware/wrap-formats]], :conflicting true, :status 302, :headers {"Location" "/home"}, :body ""}, :scope :get} 

plexus12:07:17

hmmm not sure, I do think you should add a parameter to (fn [] (found "/wiki/home")), like (fn [_req] (found "/wiki/home"))

3
theequalizer7312:07:23

I made some changes and it stopped complaining.

(defn home-page [request]
  (found "/wiki/home")
  #_(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))


(defn render-wiki-page [request page]
  (clojure.pprint/pprint page)
  (layout/render request "wiki-page.html" page))

#_(defn about-page [request]
    (layout/render request "about.html"))

(defn home-routes []
  [""
   {:middleware [middleware/wrap-csrf
                 middleware/wrap-formats]
    :conflicting true}
   ["/"      {:get home-page}]
   ["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
                     (when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
                       (render-wiki-page request page)))}]])
Now it is redirecting just as expected! Thank you! :D

plexus13:07:50

Nice! Have you watched the ring episodes? They should give a pretty good foundation for this stuff

theequalizer7321:07:14

I watched Ring Part1, the other 5 episodes are on my list 😉 I keep jumping from here and there depending on what I need to know. I guess I have to do it in order to get the explanation on some things I dont understand sometimes.

theequalizer7312:07:23

I made some changes and it stopped complaining.

(defn home-page [request]
  (found "/wiki/home")
  #_(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))


(defn render-wiki-page [request page]
  (clojure.pprint/pprint page)
  (layout/render request "wiki-page.html" page))

#_(defn about-page [request]
    (layout/render request "about.html"))

(defn home-routes []
  [""
   {:middleware [middleware/wrap-csrf
                 middleware/wrap-formats]
    :conflicting true}
   ["/"      {:get home-page}]
   ["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
                     (when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
                       (render-wiki-page request page)))}]])
Now it is redirecting just as expected! Thank you! :D