Ruby on Rails“NoMethodError”没有任何信息

时间:2012-01-24 21:24:11

标签: ruby-on-rails ruby-on-rails-3 null nomethoderror

最终编辑中的答案

我正在使用Rails 3.1.3运行一个项目。我只有一个页面网页,我的应用程序控制器看起来像这样:

class ApplicationController < ActionController::Base
protect_from_forgery

def index
end

end

和路线

root :to => 'application#index'

在routes.rb中

当我加载页面时,我在一个正文中出现此错误:在我页面顶部的html标记之前(否则内容似乎加载正常)

NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]

我的控制台中没有显示服务器正在运行的任何内容,也没有关于错误发生位置的信息。

如您所见,我不知道从哪里开始寻找这个nil实例。谁能让我知道这里会发生什么?

编辑:包括我的routes.rb文件的内容

ProjectName::Application.routes.draw do

root :to => 'application#index'

end

最终编辑:

我让项目在不同的文件夹中运行,最近将其移动了。原来指南针抛出一个错误(因此为什么它被扔进我的身体html标签)尽管加载样式表很好。我需要运行compass clean然后compass compile,我想让Compass知道新路径。感谢大家的帮助!

这是我的Gemfile

source :gemcutter

gem 'rails', '3.1.3'

gem 'sqlite3'

gem 'json'
gem 'rails_config', '0.2.4'
gem 'jammit', '0.6.5'
gem 'compass', '0.11.3'
gem 'haml', '3.1.2'

gem 'jquery-rails'

2 个答案:

答案 0 :(得分:1)

我不认为在ApplicationController中使用任何显示方法是个好主意。尝试运行

rails g controller welcome

并添加您的index并通过

路由到此处
root :to => 'welcome#index`

修改 发布您的Gemifile后,我发现问题出在哪里。这是因为Comapss 0.11与Rails 3.1不兼容。您必须使用alpha版本。将Compass版本更改为:

gem 'compass',      '~> 0.12.alpha.0'

答案 1 :(得分:0)

也许它发生在index.html.erb文件中。请检查您是否在开发环境中运行,而不是“生产”。然后检查development.log文件。