我正在使用 Noir 开发一个 Web 应用程序。但是,我遇到了路由问题。这是我的控制器的代码示例:
(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"]]]])))
每次我请求“/users/add”时,请求都会被路由到“/user/:id”(删除/user/add 操作时很好)。我有另一个控制器的非常相似的代码,它工作正常。可能是什么问题?如何设置路由优先级?
谢谢, 雅克