Module: Glib::Json::Libs::ClassMethods
- Defined in:
- app/controllers/concerns/glib/json/libs.rb
Instance Method Summary collapse
- #json_libs_force_json_ui ⇒ Object
- #json_libs_init(options) ⇒ Object
- #json_libs_rescue_404(preview_mode: false) ⇒ Object
-
#json_libs_rescue_500(preview_mode: false) ⇒ Object
Call this before other rescues.
- #json_libs_rescue_csrf ⇒ Object
- #json_libs_set_locale ⇒ Object
- #json_libs_skip_json_ui(options = {}) ⇒ Object
Instance Method Details
#json_libs_force_json_ui ⇒ Object
299 300 301 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 299 def json_libs_force_json_ui before_action :glib_force_json_ui end |
#json_libs_init(options) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 270 def json_libs_init() include Glib::Json::Transformation include Glib::Json::Validation include Glib::Json::Ui include Glib::Json::Traversal include Glib::Json::NewDynamicText before_action do __json_ui_start() end # Note that after_action gets executed in reverse after_action do __json_ui_commit() end after_action :__json_transformation_commit after_action :__json_validate_perform after_action :__json_traversal_perform after_action :__json_traversal_register_dynamic_text end |
#json_libs_rescue_404(preview_mode: false) ⇒ Object
365 366 367 368 369 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 365 def json_libs_rescue_404(preview_mode: false) rescue_from ActiveRecord::RecordNotFound do |exception| glib_json_handle_404(exception, preview_mode) end end |
#json_libs_rescue_500(preview_mode: false) ⇒ Object
Call this before other rescues. Later rescue_from statements will take precedence, so more specific rescues have to be declared later.
359 360 361 362 363 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 359 def json_libs_rescue_500(preview_mode: false) rescue_from StandardError do |exception| glib_json_handle_500(exception, preview_mode) end end |
#json_libs_rescue_csrf ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 312 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: url # } # } # end # end respond_to do |format| format.html do redirect_to sign_in_url end format.json do render json: { glib_json_dialog_mode? ? :onLoad : :onResponse => __glib_error_dialog( 'Your session has expired', 'Please refresh the page and retry.', [ { view: 'button', text: 'Refresh', onClick: { action: 'dialogs/close', onClose: { action: 'windows/reload', onReload: { action: 'snackbars/alert', message: 'Refreshed. You can try again now.' } } } }, ] ) } end end end end |
#json_libs_set_locale ⇒ Object
303 304 305 306 307 308 309 310 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 303 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 |
#json_libs_skip_json_ui(options = {}) ⇒ Object
293 294 295 296 297 |
# File 'app/controllers/concerns/glib/json/libs.rb', line 293 def json_libs_skip_json_ui( = {}) prepend_before_action do params[:_skip_render] = 'true' end end |