这个问题真的让我很失落。
我有一个身份验证模型:用户。我有一个评论模型:comment。我有一个可评论的模型:weburl。
Weburl 1..* 评论 Weburl *..1 用户评论 *..1 用户
我遇到的问题是不可测试的(我的测试都通过了),并且不会一直发生。通常它会在我第二次生成相同的控制器动作时发生。
问题是我的用户与我的评论相关联,并通过评论检索。用户变得不等于 current_user,即使属性相同。例如 :
(comment.user.login == current_user.login == User.find(1).login)
==> True
(comment.user.id)
==> Unknown in the current context
(comment.user.class == User == current_user.class)
==> True
我仔细检查了关系belongs_to
和has_one has_many
我的模型
我的猜测是这与缓存有关,我在我的开发环境中遇到过这种情况,但在我的自动化测试和生产中都没有。
我想了解是什么问题。
谢谢
编辑 添加我的 development.rb 初始化文件
config.cache_classes = false #Set to true for prod
config.whiny_nils = true
config.action_controller.consider_all_requests_local = true #Set to false for prod
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false #Set to true for prod
编辑 #2 如果 config.cache_classes 为真,则错误不会发生
Doc 说: # 在开发环境中,您的应用程序代码在每次请求时都会重新加载。这会减慢响应时间,但非常适合开发,因为您在更改代码时不必重新启动网络服务器。
找到以下票证,可能是相互关联的http://dev.rubyonrails.org/ticket/10722 另外,Mongrel 和 WebRick 也会出现问题。