0
0
Fork 0

Replace OEmbed and initial state Rabl templates with serializers (#4110)

* Replace OEmbed Rabl template with serializer

* Replace initial state rabl with serializer
This commit is contained in:
Eugen Rochko 2017-07-08 14:51:05 +02:00 committed by GitHub
parent 102466ac58
commit 864e3f8d9c
9 changed files with 121 additions and 94 deletions

View file

@ -2,13 +2,10 @@
class HomeController < ApplicationController
before_action :authenticate_user!
before_action :set_initial_state_json
def index
@body_classes = 'app-body'
@token = current_session.token
@web_settings = Web::Setting.find_by(user: current_user)&.data || {}
@admin = Account.find_local(Setting.site_contact_username)
@streaming_api_base_url = Rails.configuration.x.streaming_api_base_url
@body_classes = 'app-body'
end
private
@ -16,4 +13,14 @@ class HomeController < ApplicationController
def authenticate_user!
redirect_to(single_user_mode? ? account_path(Account.first) : about_path) unless user_signed_in?
end
def set_initial_state_json
state = InitialStatePresenter.new(settings: Web::Setting.find_by(user: current_user)&.data || {},
current_account: current_account,
token: current_session.token,
admin: Account.find_local(Setting.site_contact_username))
serializable_resource = ActiveModelSerializers::SerializableResource.new(state, serializer: InitialStateSerializer)
@initial_state_json = serializable_resource.to_json
end
end