Ruby on rails 仅在视图中使用未定义的对象方法

Ruby on rails 仅在视图中使用未定义的对象方法,ruby-on-rails,ruby,mongodb,object,mongomapper,Ruby On Rails,Ruby,Mongodb,Object,Mongomapper,我有一个Day对象,它包含一些统计信息,并每天更新。以下是我得到的两个错误: 未定义的方法“顶光雪”# 未定义的方法“top\u agents\u snown”# 根据视图的内容: <h3 class='thin underline'>Daily Breakdown:</h3> <%# debug @today %> <%# @today.methods %> Top User Agents Today: <%= @today.top_age

我有一个Day对象,它包含一些统计信息,并每天更新。以下是我得到的两个错误:

未定义的方法“顶光雪”#

未定义的方法“top\u agents\u snown”#

根据视图的内容:

<h3 class='thin underline'>Daily Breakdown:</h3>
<%# debug @today %>
<%# @today.methods %>
Top User Agents Today: <%= @today.top_agents_snown %>
<br>
Top Keyword Triggers <%= @today.top_keyword_triggers %>
<br>
Top URLs Visited <%= @today.top_urls_visited %>
<br>
Top Injections Shown <%= @today.top_inj_shown %>
<br>
Top Popups Shown <%= @today.top_pop_shown %>
<br>
Top Custom Injections Shown <%= @today.top_cust_shown %>
<br>
Top Lightboxes Shown <%# @today.top_light_snown %>
<br>
Top Global Injections Shown <%= @today.top_glob_shown %>
以下是请求页面后的服务器日志,其中puts在控制器中工作正常:

2012年8月1日开始获取127.0.0.1版本的“/assets/favicons/favicon.ico” 19:13:03-0600服务资产/favicon/favicon.ico-304未修改(1ms)

l-TEST l-TEST2火狐浏览器

2012-08-01 19:16:38-0600开始获取127.0.0.1的“仪表板” DashboardController处理#索引为HTML

最后,这里是Day.rb的内容:

class Day
    include MongoMapper::Document
    key :number,            Integer

    key :pageviews,         Integer
    key :shown_injs,        Integer
    key :shown_pops,        Integer
    key :shown_custs,       Integer
    key :shown_lights,      Integer
    key :shown_globs,       Integer

    key :top_agents_shown,      Array
    key :top_keyword_triggers,  Array
    key :top_urls_visited,      Array
    key :top_inj_shown,     Array
    key :top_pop_shown,     Array
    key :top_cust_shown,        Array
    key :top_light_shown,       Array
    key :top_glob_shown,        Array

end

到底发生了什么事?为什么使用不同名称的相同方法有效,而其他方法无效?为什么是这两个?为什么它们在控制器中工作而不在视图中工作?

您的视图调用@today.top\u agents\u snown,但您定义了显示的top\u agents\u。只是拼错了。有些日子就是这样

您的视图调用@today.top\u agents\u snown,但您定义了显示的top\u agents。你的代码也有拼写错误吗?对不起。显示的顶级代理在模型中定义为Day的方法,然后@today成为Day.new的实例-因此它应该有该方法,否?继续添加您的答案,我会接受它。
class Day
    include MongoMapper::Document
    key :number,            Integer

    key :pageviews,         Integer
    key :shown_injs,        Integer
    key :shown_pops,        Integer
    key :shown_custs,       Integer
    key :shown_lights,      Integer
    key :shown_globs,       Integer

    key :top_agents_shown,      Array
    key :top_keyword_triggers,  Array
    key :top_urls_visited,      Array
    key :top_inj_shown,     Array
    key :top_pop_shown,     Array
    key :top_cust_shown,        Array
    key :top_light_shown,       Array
    key :top_glob_shown,        Array

end