开发者

What is causing a NoMethodError '_view_paths' exception?

First off, the exception in question:

undefined method '_view_paths' for nil:NilClass`

The related routes:

get 'payments/index' => 'payments#index'
get 'payments/class' => 'payments#class'
get 'payments/kids' => 'payments#kids'
get 'payments/donate' => 'payments#donate'

The associated controller:

class PaymentsController < ApplicationController
  def index
  end

  def class
  end

  def kids
  end

  def donate
  end
end

So, the exception occurs every time I try to access one of the routes. The views for the routes described above are the simple ones generated with scaffolding and use no other rails API calls. I can't seem to find any other information on this '_view_paths' method. The only assumption I can make thus far is that the proper view isn't being found, but all views reside exactly where 开发者_如何学JAVAexpected according to rails conventions (app/views/payments/*).

Has anyone stumbled upon this issue and found a solution?


You can't define a method named "class" as it's already a reserved method to refer to the object's class, for example:

Object.new.class #=> Object

Technically I suppose you can override it (as you have), but doing so is mostly likely going to have some bizarre consequences unless you know what you're doing.

The error is probably happening when the code tries to call something like self.class._view_paths. It expects to be calling PaymentsController._view_paths. However, you've overridden the instance method class with an empty method returning nil, hence the nil exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜