Permalink
Browse files

Changed API for manually passing the current_tenant object

  • Loading branch information...
1 parent aae31c8 commit 9237669de7616da993cbcc2c10e2313bf4b0535f @ErwinM committed Mar 24, 2012
Showing with 37 additions and 5 deletions.
  1. +4 −0 CHANGELOG.md
  2. +8 −3 README.md
  3. +24 −1 lib/acts_as_tenant/controller_extensions.rb
  4. +1 −1 lib/acts_as_tenant/version.rb
View
@@ -1,3 +1,7 @@
+0.2.7
+-----
+* Changed the interface for passing in the current_tenant manually in the controller. `set_current_tenant_to` has been deprecated and replaced by `set_current_tenant_through_filter` declaration and the `set_current_tenant` method. See readme for details.
+
0.2.6
-----
* Fixed a bug with resolving the tenant model name (thx devton!)
View
@@ -43,10 +43,15 @@ This tells acts_as_tenant to use the current subdomain to identify the current t
**OR Pass in the current tenant yourself**
class ApplicationController < ActionController::Base
- current_account = Account.find_the_current_account
- set_current_tenant_to(current_account)
+ set_current_tenant_through_filter
+ before_filter :your_method_that_finds_the_current_tenant
+
+ def your_method_that_finds_the_current_tenant
+ current_account = Account.find_it
+ set_current_tenant(current_account)
+ end
end
-This allows you to pass in the current tenant yourself.
+Setting the current_tenant yourself, requires you to declare `set_current_tenant_through_filter` at the top of your application_controller to tell acts_as_tenant that you are going to use a before_filter to setup the current tenant. Next you should actually setup that before_filter to fetch the current tenant and pass it to `acts_as_tenant` by using `set_current_tenant(current_tenant)` in the before_filter.
**note:** If the current tenant is not set by either of these methods, Acts_as_tenant will be unable to apply the proper scope to your models. So make sure you use one of the two methods to tell acts_as_tenant about the current tenant.
@@ -31,13 +31,36 @@ def current_tenant
end
end
+ # This method sets up a method that allows manual setting of the current_tenant. This method should
+ # be used in a before_filter. In addition, a helper is setup that returns the current_tenant
+ def set_current_tenant_through_filter
+ self.class_eval do
+ helper_method :current_tenant
+
+ def set_current_tenant(current_tenant_object)
+ ActsAsTenant.current_tenant = current_tenant_object
+ end
+
+ private
+ # helper method to have the current_tenant available in the controller
+ def current_tenant
+ ActsAsTenant.current_tenant
+ end
+ end
+ end
+
+
+
# this method allows manual setting of the current_tenant by passing in a tenant object
#
def set_current_tenant_to(current_tenant_object)
self.class_eval do
cattr_accessor :tenant_class
attr_accessor :current_tenant
- before_filter lambda { @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object }
+ before_filter lambda {
+ ActiveSupport::Deprecation.warn "set_current_tenant_to is deprecated and will be removed from Acts_as_tenant in a future releases, please use set_current_tenant_through_filter instead.", caller
+ @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object
+ }
helper_method :current_tenant
@@ -1,3 +1,3 @@
module ActsAsTenant
- VERSION = "0.2.6"
+ VERSION = "0.2.7"
end

0 comments on commit 9237669

Please sign in to comment.