当前租户的Rails范围

时间:2013-08-13 14:38:54

标签: ruby-on-rails

我有一个多租户Rails应用程序。

我在每个模型中使用这行代码:

default_scope { where(tenant_id: Tenant.current_id) }

我有一个名为worequest的模型,它包含一个名为request_closed的整数列。我希望每个租户都能定义哪个statuscode已关闭。

default_scope语句之后,我正在尝试为未关闭的请求设置范围。

我尝试过以下操作但它们不起作用:

scope :closed, where(:statuscode_id => Tenant.current.request_closed)
scope :closed, where(:statuscode_id => current_tenant.request_closed)
scope :closed, where(:statuscode_id => Tenant.request_closed)
scope :closed, where(:statuscode_id => Tenant.current_id.request_closed)

有可能做我想做的事吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

看到request_closedTenant上的属性,您需要使用current_id值检索当前租户,然后在其上调用。

Tenant.find(Tenant.current_id).request_closed
相关问题