Module: Glib::Json::Libs::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#json_libs_force_json_uiObject



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

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



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

def json_libs_init(options)
  include Glib::Json::Transformation
  include Glib::Json::Validation
  include Glib::Json::Ui
  include Glib::Json::DynamicText

  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_dynamic_text_perform
  after_action :__json_validate_perform
end

#json_libs_rescue_csrfObject



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

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



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

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