ActionController :: RoutingError(未定义的方法'sub'代表nil:NilClass)

时间:2012-02-22 02:25:18

标签: ruby-on-rails

当我尝试查看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

控制器/ galleries_controller.rb:

class GalleriesController < ApplicationController
  def index

  end
end

views / galleries / index.html.erb为空

知道这意味着什么吗?

1 个答案:

答案 0 :(得分:8)

当路由器尝试查找常量名称并失败时,通常会发生此问题。

你有app / helpers / galleries_helper.rb的助手吗?如果是这样,它是否定义了GalleriesHelper?