0

我的heroku部署遇到了问题。这是日志:

   2014-04-29T16:41:59.782999+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
    2014-04-29T16:41:59.782933+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
    2014-04-29T16:41:59.804819+00:00 app[web.1]: 
    2014-04-29T16:41:59.804823+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
    2014-04-29T16:41:59.804826+00:00 app[web.1]:   app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'
    2014-04-29T16:41:59.804824+00:00 app[web.1]:   config/initializers/paper_trail.rb:4:in `user'
    2014-04-29T16:41:59.804854+00:00 app[web.1]:   app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
    2014-04-29T16:41:59.804828+00:00 app[web.1]:   app/views/lines/_history.html.erb:4:in `each'
    2014-04-29T16:41:59.804856+00:00 app[web.1]:   app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
    2014-04-29T16:41:59.804869+00:00 app[web.1]:   app/views/lines/_history.html.erb:4:in `each'
    2014-04-29T16:41:59.804871+00:00 app[web.1]:   app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
    2014-04-29T16:41:59.804872+00:00 app[web.1]:   app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
    2014-04-29T16:41:59.804875+00:00 app[web.1]: 
    2014-04-29T16:41:59.804874+00:00 app[web.1]: 
    2014-04-29T16:41:59.804857+00:00 app[web.1]: 
    2014-04-29T16:41:59.804858+00:00 app[web.1]: 
    2014-04-29T16:41:59.804864+00:00 app[web.1]: 
    2014-04-29T16:41:59.804865+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
    2014-04-29T16:41:59.804866+00:00 app[web.1]:   config/initializers/paper_trail.rb:4:in `user'
    2014-04-29T16:41:59.804868+00:00 app[web.1]:   app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'

有问题的初始化程序如下:

module PaperTrail
  class Version < ActiveRecord::Base
    def user
      User.find self.whodunnit.to_i
    end

    def nextversion
        self.next
    end
  end
end

在 _history 视图中调用以下内容:

<%= gravatar_for version.user %><%= link_to  version.user.username, user_path(version.user) %>

这在开发中运行良好,并且在大多数编辑页面上似乎在生产中运行良好,但在一个我遇到此错误。我想在控制台中检查版本,但似乎我根本无法在控制台中访问 paper_trail 版本,我只能假设这是因为我没有版本模型,只有一个表和一个控制器。

我怎样才能解决这个问题?

4

2 回答 2

0

您可能没有运行您的 seed.rb 文件(heroku run rake db:seed)来创建用户,或者您只是在寻找一个不再定义的用户(例如删除)。

当您删除一个 id=0 的用户时,下一个用户的 id=1。

可以肯定的是,o 建议您在控制台上输入(heroku 运行控制台)并尝试自己找到它(Client.find(0))或尝试列出所有这些(Client.all)以查看用户是否使用id=0 已定义。

希望能帮助到你

于 2014-04-29T17:15:15.893 回答
0

您收到以下错误

ActiveRecord::RecordNotFound (Couldn't find User with id=0)

关于以下方法

def user
  puts "Value of whodunnit is -----------> #{self.whodunnit}"
  User.find self.whodunnit.to_i
end

这被称为

<%= gravatar_for version.user %><%= link_to  version.user.username, user_path(version.user) %>

因为self.whodunnit.to_i正在回归0。这意味着,whodunnit要么是要么""或。请设置正确的属性值。此外,您可以通过在方法中添加or语句来检查当前值。nil0whodunnitwhodunnitloggerputsPaperTrail::Version# user

于 2014-04-29T17:22:04.807 回答