Created
December 15, 2016 10:33
-
-
Save bogdan/95f0fa672840025e18e169dda570d50c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loads @site into controller and check if current user is authorized | |
# to view this site. | |
module SiteNestedController | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :site_param | |
self.site_param = :site_id | |
before_action :require_user | |
around_action :load_site | |
end | |
protected def load_site | |
@site = Site.find(params[self.class.site_param]) | |
@site.with_tz do | |
if @site.authorizes?(current_user) | |
session[:current_site_id] = @site.id | |
yield | |
else | |
access_denied | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment