Download app/controllers/application_controller.rb from denise-oneill-inbox-ru/Rails-8-API-Image-Processing: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/application_controller.rb
- Command line
-
hf download hf://spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/app/controllers/application_controller.rb
-
curl -L -o application_controller.rb https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/application_controller.rb
1.36 kB
| class ApplicationController < ActionController::Base | |
| include Pundit::Authorization | |
| include Pagy::Method | |
| allow_browser versions: :modern | |
| stale_when_importmap_changes | |
| before_action :set_locale | |
| before_action :set_paper_trail_whodunnit | |
| before_action :authenticate_user!, unless: :devise_or_static_controller? | |
| rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized | |
| layout :resolve_layout | |
| def default_url_options | |
| { locale: I18n.locale } | |
| end | |
| private | |
| def user_for_paper_trail | |
| current_user&.id&.to_s | |
| end | |
| def info_for_paper_trail | |
| { | |
| request_ip: request.remote_ip, | |
| request_path: request.path | |
| } | |
| end | |
| def devise_or_static_controller? | |
| is_a?(DeviseController) || is_a?(StaticController) | |
| end | |
| def resolve_layout | |
| is_a?(DeviseController) ? "devise" : "application" | |
| end | |
| def set_locale | |
| locale = params[:locale] || session[:locale] || I18n.default_locale | |
| locale = locale.to_sym if locale.is_a?(String) | |
| I18n.locale = I18n.available_locales.include?(locale) ? locale : I18n.default_locale | |
| session[:locale] = I18n.locale if params[:locale].present? | |
| end | |
| def user_not_authorized | |
| flash[:alert] = t("errors.not_authorized") | |
| redirect_back(fallback_location: root_path_with_locale) | |
| end | |
| def root_path_with_locale | |
| localized_root_path(I18n.locale) | |
| end | |
| end | |