TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.94k stars 173 forks source link

Implementing rescue_from #422

Closed djolereject closed 1 year ago

djolereject commented 1 year ago

I'm trying to add rescue_from to all Trestle controllers and can't find the way to do so. My idea was to do something in config/initializers/trestle.rb, but it appears I can't just access Trestle::AdminController nor Trestle::ApplicationController. Is there any way of doing this?

Partytray commented 1 year ago

this is really gross, but it could work:

module ABadHack
  extend ActiveSupport::Concern

  included do
    rescue_from ActiveRecord::RecordNotFound do
      # ... 
    end
  end
end

module Trestle
  def self.resource(name, options={}, &block)
    object = Resource::Builder.create(name, options, &block)
    object.const_get(:AdminController).include ABadHack
    register(object)
  end
end
djolereject commented 1 year ago

Thanks, I thought of something similar, but you are right in that it's really not pretty :)