我的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
在历史记录视图中调用以下内容(_H):
<%= gravatar_for version.user %><%= link_to version.user.username, user_path(version.user) %>
这在开发中运行良好,在大多数编辑页面的生产中似乎运行良好,但在一个页面上我遇到了这个错误。我想检查控制台中的版本,但似乎我根本无法访问控制台中的paper_track版本,我只能假设这是因为我没有版本模型,只有一个表和一个控制器。
我该怎么解决这个问题?
您得到以下错误
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) %>
因为CCD_ 2正在返回CCD_。也就是说,whodunnit
是""
或者nil
或者0
。请设置正确的whodunnit
属性值。此外,您可以通过在PaperTrail::Version# user
方法中添加logger
或puts
语句来检查whodunnit
的当前值。
您可能没有运行seed.rb文件(heroku run rake db:seed)来创建用户,或者您只是在寻找一个不再定义的用户(例如已删除的用户)。
删除id为0的用户时,下一个用户的id将为1。
当然,o建议您在控制台(heroku运行控制台)上输入,并尝试自己查找(Client.find(0))或尝试列出所有用户(Client.all),以查看是否定义了id为0的用户。
希望它能帮助