Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow base controller customization #78

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ config.action_mailer.delivery_method = :letter_opener_web
config.action_mailer.delivery_method = ENV['USER'] == 'vagrant' ? :letter_opener_web : :letter_opener
```

If you're using `:letter_opener_web` as your delivery method, you can change the location of the letters by adding the
If you're using `:letter_opener_web` as your delivery method and you want to customize some options then you can add the
following to an initializer (or in development.rb):

```ruby
LetterOpenerWeb.configure do |config|
# change the location of the letters
config.letters_location = Rails.root.join('your', 'new', 'path')

# change the base controller (if you want to avoid the execution of filters set on the ApplicationController of your
# application then use LetterOpenerWeb::ApplicationController)
config.base_controller = YourNewBaseController
end
```

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/letter_opener_web/letters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module LetterOpenerWeb
class LettersController < ApplicationController
class LettersController < LetterOpenerWeb.config.base_controller
before_action :check_style, only: [:show]
before_action :load_letter, only: %i[show attachment destroy]

Expand Down
2 changes: 2 additions & 0 deletions lib/letter_opener_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
module LetterOpenerWeb
class Config
attr_accessor :letters_location
attr_accessor :base_controller
end

def self.config
@config ||= Config.new.tap do |conf|
conf.letters_location = Rails.root.join('tmp', 'letter_opener')
conf.base_controller = ApplicationController
end
end

Expand Down