Created
August 22, 2016 11:26
-
-
Save Agowan/d67df4c412f12f009c904cfa97060186 to your computer and use it in GitHub Desktop.
Slim api base controller
This file contains hidden or 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
# frozen_string_literal: true | |
module Store | |
class ApiController < ActionController::Metal | |
include ActionController::ForceSSL | |
include ActiveSupport::Rescuable | |
include AbstractController::Callbacks | |
include Authority::Controller | |
include Sorcery::Controller | |
include ActionController::Helpers | |
before_action :require_login | |
helper_method :current_user, :current_org, :logged_in? | |
def render(options = {}) | |
self.status = options[:status] || 200 | |
self.content_type = 'application/json' | |
body = options[:text] | |
body = Oj.dump(options[:json], mode: :compat) if body.nil? | |
headers['Content-Length'] = body.bytesize.to_s | |
self.response_body = body | |
end | |
def current_org | |
if session[:organization_id].present? | |
@current_org ||= ::Organization.find session[:organization_id] | |
end | |
end | |
if Rails.env.development? || Rails.env.test? | |
include ActionController::Instrumentation | |
ActiveSupport.run_load_hooks(:action_controller, self) | |
end | |
def sanitize(sql, query) | |
User.send(:sanitize_sql, [sql, query]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment