engine/app/controllers/locomotive/api/base_controller.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2012-01-23 08:05:50 +00:00
module Locomotive
module Api
class BaseController < ApplicationController
include Locomotive::Routing::SiteDispatcher
include Locomotive::ActionController::LocaleHelpers
skip_before_filter :verify_authenticity_token
2012-01-23 08:05:50 +00:00
before_filter :require_account
before_filter :require_site
before_filter :set_locale
2012-04-30 19:29:32 +00:00
before_filter :set_current_thread_variables
2012-01-23 08:05:50 +00:00
self.responder = Locomotive::ActionController::Responder # custom responder
respond_to :json, :xml
protected
2012-04-30 19:29:32 +00:00
def set_current_thread_variables
Thread.current[:account] = current_locomotive_account
Thread.current[:site] = current_site
end
2012-01-23 08:05:50 +00:00
def current_ability
@current_ability ||= Ability.new(current_locomotive_account, current_site)
end
def require_account
authenticate_locomotive_account!
end
def set_locale
::Mongoid::Fields::I18n.locale = params[:locale] || current_site.default_locale
::I18n.locale = ::Mongoid::Fields::I18n.locale
self.setup_i18n_fallbacks
end
2012-01-23 08:05:50 +00:00
end
end
2012-04-17 13:12:42 +00:00
end