0

我从 heroku 日志中收到此错误。我的应用程序正在使用 mongoid 和 MongoHQ 数据库。它在我的本地机器上运行良好。

2013-05-29T12:08:04.219051+00:00 app[web.1]:   Rendered posts/index.html.erb within layouts/application (7.5ms)
2013-05-29T12:08:04.219266+00:00 app[web.1]: Completed 500 Internal Server Error in 8ms
2013-05-29T12:08:04.221331+00:00 app[web.1]: 
2013-05-29T12:08:04.221331+00:00 app[web.1]: ActionView::Template::Error (undefined method `[]' for nil:NilClass):
2013-05-29T12:08:04.221331+00:00 app[web.1]:     12:     <th class="span1"></th>
2013-05-29T12:08:04.221331+00:00 app[web.1]:     13:   </tr>
2013-05-29T12:08:04.221331+00:00 app[web.1]:     14: 
2013-05-29T12:08:04.221331+00:00 app[web.1]:     15: <% @posts.each do |post| %>
2013-05-29T12:08:04.221331+00:00 app[web.1]:     16:   <tr class="row-fluid">
2013-05-29T12:08:04.221331+00:00 app[web.1]:     17:     <td class="span2"><%= post.title %></td>
2013-05-29T12:08:04.221331+00:00 app[web.1]:     18:     <td class="span1"><%= post.post_date %></td>
2013-05-29T12:08:04.221331+00:00 app[web.1]:   app/views/posts/index.html.erb:15:in `_app_views_posts_index_html_erb___2127098936622691725_37166920'
2013-05-29T12:08:04.221586+00:00 app[web.1]:   app/controllers/posts_controller.rb:12:in `index'

在使用之前我必须对 MongoHQ 做任何事情吗?

这是索引操作的代码:

  def index
    t = params[:t].to_i
    if t
      @posts = Post.where(:created_at.gt => t).asc(:created_at)
    else
      @posts = Post.all
    end

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end
4

0 回答 0