Rails Admin works locally for me, but when I deploy to Heroku, it fails with:
ActionView::Template::Error (The asset "rails_admin/rails_admin.css" is not present in the asset pipeline
I am on Rails 5.2.6 and Rails Admin 2.0.2
I added initializers/assets.rb with this line:
Rails.application.config.assets.precompile += ['rails_admin/rails_admin.css', 'rails_admin/rails_admin.js']
but those files do not exist in assets/javascripts and assets/stylessheets.
This app was originally built as an API only app, but I've added all the missing middleware to make it work as a normal Rails app.
This is my application.rb:
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module CheckwizApi
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = false
# use uuid's as primary_key
config.active_record.primary_key = :uuid
config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
end
config.i18n.default_locale = :en
config.active_job.queue_adapter = :sidekiq
# Added because RailsAdmin needs them
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Flash
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Session::CookieStore
end
end
Note that I have set config.api_only = false and added back the required middleware, but to no avail. If I set it to true, same error.
If I remove the assets file I added above, same error.
The assets/javascripts and assets/stylesheets folders are empty. Is that the problem?
I have looked at several other closed issues related to this and most of them advise adding the above middleware, or clearing tmp/cache and restarting. Neither worked for me sadly.