[英]Heroku can't find user but works in dev
我在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版本,我只能假設這是因為我沒有版本模型,只有一個表和一個控制器。
我怎樣才能解決這個問題?
您可能沒有運行seed.rb文件(heroku運行rake db:seed)來創建用戶,或者您正在尋找的是不再定義的用戶(例如,已刪除)。
當您刪除ID == 0的用戶時,下一個用戶的ID = 1。
可以肯定的是,o建議您在控制台(heroku運行控制台)上輸入並嘗試自己查找(Client.find(0))或嘗試列出所有控制台(Client.all),以查看用戶是否id = 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
屬性的正確值。 另外,您可以通過在PaperTrail::Version# user
方法中添加logger
或puts
語句來檢查whodunnit
的當前值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.