From 6a358f371e490137553d6b805b3a634032a61128 Mon Sep 17 00:00:00 2001 From: Mauro Nidola Date: Wed, 7 Feb 2018 15:59:29 +0100 Subject: [PATCH 1/2] allow base controller customization --- app/controllers/letter_opener_web/letters_controller.rb | 2 +- lib/letter_opener_web.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/letter_opener_web/letters_controller.rb b/app/controllers/letter_opener_web/letters_controller.rb index a1abe2b..9777caa 100644 --- a/app/controllers/letter_opener_web/letters_controller.rb +++ b/app/controllers/letter_opener_web/letters_controller.rb @@ -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] diff --git a/lib/letter_opener_web.rb b/lib/letter_opener_web.rb index b9efa30..d709762 100644 --- a/lib/letter_opener_web.rb +++ b/lib/letter_opener_web.rb @@ -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 From ecddc3e5066adf0cb692fd3a2d5e1c3fef8c9fd6 Mon Sep 17 00:00:00 2001 From: Mauro Nidola Date: Wed, 7 Feb 2018 16:39:30 +0100 Subject: [PATCH 2/2] update readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ad591f..c0c5e4d 100644 --- a/README.md +++ b/README.md @@ -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 ```