0

最终编辑中的答案

我正在使用 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

最终编辑:

我让项目在不同的文件夹中运行,最近将它移了过来。事实证明,尽管加载样式表很好,但指南针还是抛出了一个错误(因此它被抛出到我的 body 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'
4

2 回答 2

1

我不认为在ApplicationController. 尝试运行

rails g controller welcome

并在那里添加你的index和路由到这个

root :to => 'welcome#index`

编辑 发布后,Gemifile我看到问题出在哪里。这是由于 Comapss 0.11 与 Rails 3.1 不兼容造成的。您必须使用 alpha 版本。将指南针版本更改为:

gem 'compass',      '~> 0.12.alpha.0'
于 2012-01-24T21:58:13.593 回答
0

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

于 2012-01-24T21:42:37.377 回答