Sha256: c19a00eff2a22b76f83a1f6ba305f3fea0f739aeb582683de9d38b43652f72b0
Contents?: true
Size: 907 Bytes
Versions: 56
Compression:
Stored size: 907 Bytes
Contents
module Scrivito class CmsEnv OBJ_ENV_KEY = "SCRIVITO_OBJ" def initialize(env) @env = env end def load return if env[OBJ_ENV_KEY] load_object end protected attr_reader :env def load_object env[OBJ_ENV_KEY] = begin find_obj rescue StandardError => e e end end def find_obj found_obj = if params[:id] Obj.find(params[:id]) elsif params[:permalink].present? self.class.find_permalink_by_param(params[:permalink]) else Scrivito::RequestHomepage.call(env) end found_obj end def params env["action_dispatch.request.path_parameters"] end def self.find_permalink_by_param(permalink_param) permalink = Array(permalink_param).join("/") Obj.find_by_permalink!(permalink) end end end
Version data entries
56 entries across 56 versions & 1 rubygems