【问题标题】:How can I make errors in HAML (Rails) show me the exact line where the error occurred?如何在 HAML (Rails) 中出错,向我显示发生错误的确切行?
【发布时间】:2009-11-05 18:02:38
【问题描述】:

course_templates#index 中的 NoMethodError

显示第 6 行出现的 app/views/course_templates/index.haml:

undefined method `new_course_template' for #<ActionView::Base:0x237c3e4>

提取的源代码(第 6 行附近):

3: - content_for :sidebar do  
4:   %ul.links  
5:     %li= link_to "Add a Template", new_course_template(@provider)  
6:   
7: - content_for :main do  
8:     = page_entries_info @templates  
9:

看到它说“在第 6 行附近”,错误出现在第 5 行。这个例子还不错……但在更复杂的视图或助手中几乎不可能立即找到错误。有没有我遗漏的配置?

【问题讨论】:

    标签: ruby-on-rails haml


    【解决方案1】:

    这是一个我认为应该在即将发布的 Haml 2.2.11 中修复的错误。如果您不介意使用 Haml stable branch 尝试此操作以查看行号是否正确,我将不胜感激。

    【讨论】:

    • 我尝试使用 Haml 2.2.12,但行号仍然关闭。但是当我删除 content_for 时,它们似乎是正确的......也许这是一个提示。
    • 能否提供模板的完整源代码?您似乎发现了一个我非常想修复的错误。
    • nex3 正在解决这个问题。我的研究表明,任何content_for,无论是在其余内容之前还是之后,都会导致行号不正确。
    • 我认为这是一个 PEBKAC。 Haml 2.2.12 错误报告看起来不错。
    猜你喜欢
    • 2017-05-16
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    相关资源
    最近更新 更多