I am working on a web application with Noir. However, I am experiencing problem with routing. Here's the code sample from my controller:
(defpage [:get "/users/add"] []
(common/layout
[:div.row
[:div.span12
[:div.page-header
[:h2 "Add User"]]
(form-to {:class "form-horizontal"} [:post "/users/add"]
(user-form {:id ""
:first_name ""
:last_name ""
:login ""
:email ""
:admin false
:staff false
:manager false
:customer false})
[:div.control-group
[:div.controls
(submit-button {:class "btn btn-primary"} "Edit")]])]]))
(defpage [:get "/users/:id" :id #"\d+"] {:keys [id]}
(let [user (user/get-by-id id)]
(common/layout
[:div.row
[:div.span12
[:div.page-header
[:h2 "View User"]]
[:h3 (str (user :first_name) " " (user :last_name))]
[:dl.dl-horizontal
[:dt "login"]
[:dd (user :login)]
[:dt "e-mail"]
[:dd (user :email)]
[:dt "admin"]
[:dd (if (user :admin) [:i.icon-ok ""] [:i.icon-remove ""])]
[:dt "staff"]
[:dd (if (user :staff) [:i.icon-ok ""] [:i.icon-remove ""])]
[:dt "manager"]
[:dd (if (user :manager) [:i.icon-ok ""] [:i.icon-remove ""])]
[:dt "customer"]
[:dd (if (user :customer) [:i.icon-ok ""] [:i.icon-remove ""])]]
[:div.form-actions
[:a.btn.btn-primary {:href (str "/users/" (user :id) "/edit")} "Edit"] " "
[:a.btn.btn-danger {:href (str "/users/" (user :id) "/remove")} "Remove"] " "
[:a.btn {:href "/users"} "All users"]]]])))
Every time I am requesting "/users/add", the request is being routed to "/user/:id" (it is fine when I remove /user/add action). I have very similar code for another controller and it is working fine. What might be the problem? How to set routing priorities?
Thanks, Jacek
I see a little difference in your code in comparison with routes tutorial on webnoir.org.
Yours:
(defpage [:get "/users/:id" :id #"\d+"] {:keys [id]}
On webnoir:
(defpage [:get ["/user/:id" :id #"\d+"]] {:keys [id]}
^ ^
But maybe it doesn't make a difference in the end...