Ruby on Rails“NoMethodError”没有任何信息
最终编辑中的答案
我正在使用 Rails 3.1.3 运行一个项目。我只有一页网页,我的应用程序控制器如下所示:
class ApplicationController < ActionController::Base
protect_from_forgery
def index
end
end
和一条路线
root :to =>; routes.rb 中的“application#index”
。
当我加载页面时,我在页面顶部的 body:before html 标签中收到此错误(否则内容似乎加载正常)
NoMethodError: You had a nil object when you were not getting it!您可能期望一个 Array 的实例。评估 nil 时发生错误。[]
在运行服务器的控制台中没有显示任何内容,并且没有有关错误发生位置的信息。
正如你所看到的,我不知道从哪里开始寻找这个 nil 实例。谁能告诉我这里可能发生了什么?
编辑:包括我的routes.rb 文件的内容
ProjectName::Application.routes.draw do
root :to => 'application#index'
end
最终编辑:
我让该项目在不同的文件夹中运行,并且最近将其移过来。事实证明,尽管样式表加载得很好,但指南针还是抛出了一个错误(这就是为什么它被扔进我的 body html 标签中)。我需要运行compass clean
然后compass编译
,我想让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'
ANSWER IN FINAL EDIT
I'm running a project using Rails 3.1.3. I only have one page web page and my application contoller looks like this:
class ApplicationController < ActionController::Base
protect_from_forgery
def index
end
end
and a route
root :to => 'application#index'
in routes.rb.
When I load the page I get this error in a body:before html tag at the top of my page (otherwise the content seems to load fine)
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.[]
Nothing shows up in my console where the server is running, and there is no information about where the error occurs.
As you can see, I have no idea where to start looking for this nil instance. Can anyone give me an idea of what might be going on here?
Edit: including the contents of my routes.rb file
ProjectName::Application.routes.draw do
root :to => 'application#index'
end
FINAL EDIT:
I had the project running in a different folder and recently moved it over. Turns out compass was throwing an error (thus why it was being thrown into my body html tag) despite loading the stylesheets fine. I needed to run compass clean
then compass compile
, I guess to make Compass aware of the new path. Thanks for the help everyone!
btw here is my 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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为在
ApplicationController
中拥有任何显示方法不是一个好主意。尝试运行路由到此
并添加您的
索引
并通过编辑发布您的
Gemifile
后,我看到了问题所在。这是因为 Comapss 0.11 与 Rails 3.1 不兼容造成的。您必须使用 alpha 版本。将指南针版本更改为:I don't think that it is good idea to have any display methods in
ApplicationController
. Try runand there add your
index
and route to this byEDIT
After posting your
Gemifile
I saw where is problem. It's caused by that Comapss 0.11 isn't compatible with Rails 3.1. You must use alpha release. Change Compass version to:也许它发生在index.html.erb 文件中。请检查您是否在开发环境而不是“生产环境”上运行。然后检查development.log文件。
Perhaps it's occurring in index.html.erb file. Please, check if you are running on development environment, instead of 'production.' Then check the development.log file.