Skip to content

Commit 9d10a97

Browse files
committed
Introduce base_controller_class config option
1 parent 4b32982 commit 9d10a97

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ You can configure Solid Errors via the Rails configuration object, under the `so
161161
* `email_from` - The email address to send a notification from. See [Email notifications](#email-notifications) for more information.
162162
* `email_to` - The email address(es) to send a notification to. See [Email notifications](#email-notifications) for more information.
163163
* `email_subject_prefix` - Prefix added to the subject line for email notifications. See [Email notifications](#email-notifications) for more information.
164+
* `base_controller_class` - Specify a different controller as the base class for the Solid Errors controller. See [Authentication](#authentication) for more information.
164165

165166
#### Database Configuration
166167

@@ -207,6 +208,13 @@ authenticate :user, -> (user) { user.admin? } do
207208
end
208209
```
209210

211+
You can also specify a different controller to use as the Solid Errors controller base class:
212+
213+
```ruby
214+
# Override the base controller class with your own controller
215+
config.solid_errors.base_controller_class = "YourAdminController"
216+
```
217+
210218
#### Email notifications
211219

212220
Solid Errors _can_ send email notifications whenever an error occurs, if your application has ActionMailer already properly setup to send emails. However, in order to activate this feature you must define the email address(es) to send the notifications to. Optionally, you can also define the email address to send the notifications from (useful if your email provider only allows emails to be sent from a predefined list of addresses) or simply turn off this feature altogether. You can also define a subject prefix for the email notifications to quickly identify the source of the error.

app/controllers/solid_errors/application_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module SolidErrors
2-
class ApplicationController < ActionController::Base
2+
class ApplicationController < SolidErrors.base_controller_class.constantize
3+
layout "solid_errors/application"
34
protect_from_forgery with: :exception
45

56
http_basic_authenticate_with name: SolidErrors.username, password: SolidErrors.password if SolidErrors.password

lib/solid_errors.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
module SolidErrors
99
mattr_accessor :connects_to
10+
mattr_accessor :base_controller_class, default: "::ActionController::Base"
1011
mattr_writer :username
1112
mattr_writer :password
1213
mattr_writer :send_emails
@@ -21,8 +22,6 @@ def username
2122
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
2223
end
2324

24-
# use method instead of attr_accessor to ensure
25-
# this works if variable set after SolidErrors is loaded
2625
def password
2726
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
2827
end

test/test_solid_errors.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ class TestSolidErrors < Minitest::Test
66
def test_that_it_has_a_version_number
77
refute_nil ::SolidErrors::VERSION
88
end
9+
10+
def test_default_base_controller
11+
assert_equal ActionController::Base, SolidErrors::ApplicationController.superclass
12+
end
913
end

0 commit comments

Comments
 (0)