【发布时间】:2016-01-12 01:09:45
【问题描述】:
有什么方法可以从会话中初始化记录。例如,我有一个组织对象,我把它放在会话对象中,比如
session[:organization] = organization
现在我做了一个自定义方法current_organization(我知道设计) 喜欢
def current_organization
Organization.new(session[:organization])
end
这将返回组织对象。我的 organization belongs_to team 一个设计模型和 team has_many :organizations 但是当我打电话时
current_team.organizations.includes?(current_organization)
在视图中。即使它包含在团队的组织中但这样做也会返回错误
current_team.organizations.reload.includes?(current_organization)
正在返回 true。在调用我使用上述方法的视图之前,我使用组织对象设置了会话变量。是否有任何我错过的事情,比如我无法弄清楚即使包含在内也不返回 true 的原因?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 devise