53 lines
1.8 KiB
Ruby
53 lines
1.8 KiB
Ruby
# Patches for ActiveAdmin 3.4.0 compatibility with Rails 8.0
|
|
# Fixes ActionController::UrlGenerationError caused by passing `params:` to `url_for`.
|
|
|
|
Rails.logger.info "Applying ActiveAdmin Rails 8 Patches..."
|
|
|
|
require 'active_admin/views/components/scopes'
|
|
|
|
# Patch 1: Scopes - Class override (Fixes UrlGenerationError)
|
|
ActiveAdmin::Views::Scopes.class_eval do
|
|
def build_scope(scope, options)
|
|
li class: classes_for_scope(scope) do
|
|
begin
|
|
p = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params.to_h
|
|
current_params = p.symbolize_keys.except(:page, :scope, :commit, :format, :_method, :authenticity_token, :utf8)
|
|
link_options = current_params.merge(scope: scope.id)
|
|
|
|
a href: controller.url_for(link_options), class: "table_tools_button" do
|
|
text_node scope_name(scope)
|
|
span class: "count" do
|
|
"(#{get_scope_count(scope)})"
|
|
end if options[:scope_count] && get_scope_count(scope)
|
|
end
|
|
rescue => e
|
|
Rails.logger.error "ActiveAdmin Scope Patch Error: #{e.message}"
|
|
a href: "#", class: "table_tools_button error" do
|
|
text_node scope_name(scope)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Patch 2: Global UrlHelper patch for ArgumentError
|
|
# Fixes "arguments passed to url_for can't be handled" which happens in ActiveAdmin download links
|
|
module ActionView
|
|
module Helpers
|
|
module UrlHelper
|
|
alias_method :original_url_for_before_patch, :url_for
|
|
|
|
def url_for(options = nil)
|
|
begin
|
|
original_url_for_before_patch(options)
|
|
rescue ArgumentError => e
|
|
if e.message.include?("arguments passed to url_for can't be handled")
|
|
Rails.logger.error "UrlHelper Patch rescued ArgumentError for #{options.inspect}"
|
|
return "#"
|
|
end
|
|
raise e
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |