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

发布于 2024-12-28 13:15:28 字数 1129 浏览 0 评论 0原文

最终编辑中的答案

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2025-01-04 13:15:28

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

rails g controller welcome

路由到此

root :to => 'welcome#index`

并添加您的索引并通过编辑
发布您的Gemifile后,我看到了问题所在。这是因为 Comapss 0.11 与 Rails 3.1 不兼容造成的。您必须使用 alpha 版本。将指南针版本更改为:

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

I don't think that it is good idea to have any display methods in ApplicationController. Try run

rails g controller welcome

and there add your index and route to this by

root :to => 'welcome#index`

EDIT
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:

gem 'compass',      '~> 0.12.alpha.0'
伊面 2025-01-04 13:15:28

也许它发生在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文