Search code examples
ruby-on-railsroutesformatruby-on-rails-5nomethoderror

NoMethodError Undefined Method `formats` for `modify`:String


I have a method named "modify" inside my PurchaseOrdersController, it also has its template (modify.slim) inside the view directory.

Let say, I'm on this path http://localhost:3000/purchase_orders/modify?prid=1

The problem is when I'm going to click the anchor tag ('/po/1.pdf') which opens newtab, the:

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

occurs when I hit refresh the page http://localhost:3000/purchase_orders/modify?prid=1.

Does anyone has the idea how to fix this? I'm using Rails 5.2.1.

Thanks.

UPDATE: please see Rails Logs, Code: Controller, View


Solution

  • In order for Rails to properly load files, make sure any modules you have included are done so inside the respective class. For example:

    class MyClass
      include ActionView::Helpers
    end
    

    See this post for more details.