【问题标题】:Why does ring give me error in this response?为什么 ring 在此响应中给我错误?
【发布时间】:2012-09-01 01:38:28
【问题描述】:

下面是我的应用 -

(ns mfaiz.routes
  (:use [net.cgrand.moustache :only [app]]
        [net.cgrand.enlive-html :only [deftemplate content]]
        [ring.util.response :only [response]]))

(deftemplate reg "mfaiz/templates/reg.html" [])

(def my-app (app
             ["hi"] "Hello World!"
             ["reg"] (-> ((-> "reg" symbol resolve)) response constantly) 
             [&] "Nothing was found"))

我在这条路线上遇到错误 -

["reg"] (-> ((-> "reg" symbol resolve)) response constantly) 

如果我直接评估上述路线,它可以正常工作并返回 html 文件 -

((-> "reg" symbol resolve)) 

如果我也将路由更改为直接调用模板函数,那么它也可以工作 -

["reg"] (-> (reg) response constantly)

有什么想法吗?

【问题讨论】:

  • 尝试使用(-> "mfaiz.routes/reg" symbol resolve)
  • @Ankur 谢谢,这就像一个魅力! Ankur 为什么我需要指定 ns,当符号存在于 ns 中时。没有repl中的ns资格,评估也是成功的,为什么会这样?
  • 你也可以将它作为答案发布,我会标记它。

标签: clojure ring


【解决方案1】:

问题似乎是当它在环下运行时,“reg”没有被解析,因为它不是完全合格的。这取决于环服务器在哪个命名空间中启动。所以使用完全限定名称将起作用:

(-> "mfaiz.routes/reg" symbol resolve)

请查看resolvedocumentation。它尝试解析当前命名空间中的符号,即*ns*

【讨论】:

    猜你喜欢
    • 2017-04-10
    • 1970-01-01
    • 2020-10-18
    • 2020-02-27
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多