Module: Application::Json::Libs::ClassMethods

Defined in:
app/controllers/concerns/application/json/libs.rb

Instance Method Summary collapse

Instance Method Details

#json_libs_force_json_uiObject



68
69
70
71
72
73
74
# File 'app/controllers/concerns/application/json/libs.rb', line 68

def json_libs_force_json_ui
  before_action do
    if params[:_render] != 'v1'
      redirect_to url_for(params.to_unsafe_h.merge(_render: 'v1'))
    end
  end
end

#json_libs_init(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/concerns/application/json/libs.rb', line 44

def json_libs_init(options)
  include Application::Json::Transformation
  include Application::Json::Validation
  include Application::Json::Ui

  before_action :__json_ui_start

  # Note that after_action gets executed in reverse
  after_action do
    __json_ui_commit(options)
  end
  after_action :__json_transformation_commit
  after_action :__json_validate_perform
end

#json_libs_rescue_csrfObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/concerns/application/json/libs.rb', line 76

def json_libs_rescue_csrf
  rescue_from ActionController::InvalidAuthenticityToken do |exception|
    sign_out(:user)

    respond_to do |format|
      format.json do
        render json: {
          onResponse: {
            action: 'windows/open-v1',
            url: root_url
          }
        }
      end
    end
  end
end

#json_libs_set_localeObject



59
60
61
62
63
64
65
66
# File 'app/controllers/concerns/application/json/libs.rb', line 59

def json_libs_set_locale
  before_action do
    # Need to explicitly fallback to EN
    I18n.locale = params[:_locale] || :en
  rescue
    I18n.locale = :en
  end
end