【问题标题】:NoMethodError Undefined Method `formats` for `modify`:StringNoMethodError Undefined Method `formats` for `modify`:String
【发布时间】:2019-03-22 03:22:23
【问题描述】:

我的 PurchaseOrdersController 中有一个名为“modify”的方法,它在视图目录中也有它的模板 (modify.slim)。

比方说,我在这条路上http://localhost:3000/purchase_orders/modify?prid=1

问题是当我要点击打开newtab的锚标签('/po/1.pdf')时,:

NoMethodError (undefined method formats for "modify":String Did you mean? form_tag):

当我点击刷新页面http://localhost:3000/purchase_orders/modify?prid=1时发生。

有人知道如何解决这个问题吗?我正在使用 Rails 5.2.1。

谢谢。

更新:请参阅Rails LogsCode: Controller, View

【问题讨论】:

  • 信息不足,无法调试,能否显示控制器并查看相应操作的代码。
  • 你能提供异常的完整堆栈跟踪吗? Rails 服务器日志显示在抛出异常之前请求的路由位置。
  • 我添加了 Rails 日志链接,@ScottBartell 先生用于调试。
  • 您是否在类中包含任何模块? stackoverflow.com/a/23472072/1298944
  • @ScottBartell,是的! class PurchaseOrderReportPdf < Prawn::Document...end 在该行之前有 include ActionView::Helpers。我删除了它,现在错误消失了!非常感谢!!! :D

标签: ruby-on-rails routes format ruby-on-rails-5 nomethoderror


【解决方案1】:

为了让 Rails 正确加载文件,请确保您包含的所有模块都在相应的类中完成。例如:

class MyClass
  include ActionView::Helpers
end

this post for more details

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 2015-03-19
    • 2016-08-13
    • 1970-01-01
    • 2011-09-05
    • 2016-01-02
    • 2012-08-08
    相关资源
    最近更新 更多