Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created December 15, 2016 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan/95f0fa672840025e18e169dda570d50c to your computer and use it in GitHub Desktop.
Save bogdan/95f0fa672840025e18e169dda570d50c to your computer and use it in GitHub Desktop.
# 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