Closed coding-bunny closed 2 years ago
@coding-bunny can you share a bit how your rails_admin
initializer is set up (specifically, the model configs)? Have you tried the branch from https://github.com/railsadminteam/rails_admin/pull/3541 to see if that helps mitigate it?
# frozen_string_literal: true
::RailsAdmin.config do |config|
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
require ::Rails.root.join('lib', 'rails_admin', 'insights.rb')
::RailsAdmin::Config::Actions.register(::RailsAdmin::Config::Actions::Insights)
# Model Configuration
#
# Configures the Models for Rails Admin, doing it here removes all the circular warnings.
config.included_models = %w[Deployment Rollback Application]
config.model('Deployment') do
list do
sort_by :deployed_at
field :application_name do
label { 'Application' }
end
field :environment
field :host do
label { 'Destination' }
pretty_value do
view = bindings[:view]
is_k8s = bindings[:object].application&.k8s?
environment = bindings[:object].environment
url = ::RailsAdminHelper.argo_url(environment)
raw_value = value || '-'
is_k8s ? view.link_to(value, "#{url}/#{value}", target: '_blank', rel: 'noopener') : raw_value
end
end
field :branch
field :deployed_at
field :current do
filterable true
label { 'Current?' }
formatted_value { bindings[:object].current? }
pretty_value { bindings[:object].current? || '-' }
export_value { bindings[:object].current? }
end
end
show do
field :application_name do
label { 'Application' }
end
field :environment
field :host do
label { 'Destination' }
pretty_value do
view = bindings[:view]
is_k8s = bindings[:object].application&.k8s?
environment = bindings[:object].environment
url = ::RailsAdminHelper.argo_url(environment)
raw_value = value || '-'
is_k8s ? view.link_to(value, "#{url}/#{value}", target: '_blank', rel: 'noopener') : raw_value
end
end
field :branch
field :version do
pretty_value do
view = bindings[:view]
url = bindings[:object].application&.repo_url
url.blank? ? value : view.link_to(value, "#{url}/commit/#{value}", target: '_blank', rel: 'noopener')
end
end
field :deployed_by
field :deployed_at
end
end
config.model('Application') do
list do
sort_by :name
field :name
field :deployment_type
field :repo_url
end
show do
field :name
field :deployment_type
field :repo_url
end
end
config.actions do
# mandatory
dashboard
# mandatory
index
# Our own insights plugin
insights
export
# bulk_delete
show
# edit
# delete
# show_in_app
## With an audit adapter, you can add:
# history_index
# history_show
end
end
That's our initializer, so we are using the String approach for configuring the models. Everything works though, it's just that error/warning keeps popping up during the asset precompile since we don't have database access at that point.
We had this issue on heroku. Then had it after we migrated off heroku due to the fact that assets:precompile
happens on a separate instance, which does not have access to the db. This is what I did to fix the problem:
# lib/tasks/assets.rake
namespace :assets do
desc 'Set rails-admin loading env variable'
task :set_precompiling_assets_env do
ENV['PRECOMPILING_ASSETS'] = 'true'
end
end
Rake::Task['assets:environment'].enhance(['assets:set_precompiling_assets_env'])
# config/initializers/rails_admin.rb
if ENV['PRECOMPILING_ASSETS'].blank?
RailsAdmin.config do |config|
end
end
I have no idea why pre 3.0 worked and 3.0 didn't but it seems to be class/object loading issues.
Oh right, could just return
at the top of the file if that variable is set and skip the initialization.
That's actually a pattern we do more often for gems 😅
Will go with that approach for now
Closed by #3541.
Describe the bug
Reproduction steps
Expected behavior
Additional context
rails
version: 7.0.3rails_admin
version: 3.0.0rails_admin
npm package version: /Add any other context about the problem here.