当我尝试查看 localhost:3000/galleries
路由错误
undefined method `sub' for nil:NilClass
我的日志文件告诉我
ActionController::RoutingError (undefined method ‘sub’ for nil:NilClass)`
app/controllers/galleries_controller.rb:1:in `<top (required)>'
Rendered /Users/mikev/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)
routes.rb
Gallery::Application.routes.draw do
match 'galleries' => 'galleries#index'
end
Controller /galleries_controller.rb:
class GalleriesController < ApplicationController
def index
end
end
views/galleries/index.html.erb 为空
知道这意味着什么吗?
最佳答案
此问题通常发生在路由器尝试查找常量名但失败时。
你有 app/helpers/galleries_helper.rb 中的助手吗?如果是,它是否定义了 GalleriesHelper?
关于ruby-on-rails - ActionController::RoutingError(nil:NilClass 的未定义方法 ‘sub’),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9388299/