我遇到了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版本,我只能假设这是因为我没有版本模型,只有表格和控制器。
我该如何解决这个问题?
答案 0 :(得分:0)
您可能没有运行seed.rb文件(heroku运行rake db:seed)来创建用户,或者您正在寻找一个未定义的用户(例如已删除)。
当您删除id = 0的用户时,下一个用户将具有id = 1。
可以肯定的是,o建议您进入控制台(heroku运行控制台)并尝试自己找到它(Client.find(0))或尝试列出所有这些(Client.all)以查看是否定义了id = 0的用户。
希望有所帮助
答案 1 :(得分: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
可以是""
或nil
或0
。请设置whodunnit
属性的正确值。此外,您可以通过在whodunnit
方法中添加logger
或puts
语句来检查PaperTrail::Version# user
的当前值。