Sha256: 278f758db0265a78eeab645e612dd77226fc63077cae7761713974e8c52b4a44

Contents?: true

Size: 841 Bytes

Versions: 8

Compression:

Stored size: 841 Bytes

Contents

module ActiveRecordSurveyApi
	class ApplicationController < ActionController::Base
		before_filter :set_locale

		def serialize_model(model, options = {})
			options[:is_collection] = false
			((options[:serializer]) ? options[:serializer] : JSONAPI::Serializer).serialize(model, options)
		end

		def serialize_models(models, options = {})
			options[:is_collection] = true
			((options[:serializer]) ? options[:serializer] : JSONAPI::Serializer).serialize(models, options)
		end

		private
			def set_locale
				# If a language is sent - it's the preferred language!
				if !request.headers[:HTTP_ACCEPT_LANGUAGE].to_s.empty?
					http_accept_language.user_preferred_languages = [request.headers[:HTTP_ACCEPT_LANGUAGE].to_s] 
				end

				I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
			end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.19 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.18 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.17 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.14 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.12 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.11 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.7 app/controllers/active_record_survey_api/application_controller.rb
active_record_survey_api-0.0.6 app/controllers/active_record_survey_api/application_controller.rb