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

Execution of ApplicationController filters #76

Closed
mauro-ni opened this issue Jan 22, 2018 · 5 comments · Fixed by michiomochi/letter_opener_web#1
Closed

Execution of ApplicationController filters #76

mauro-ni opened this issue Jan 22, 2018 · 5 comments · Fixed by michiomochi/letter_opener_web#1

Comments

@mauro-ni
Copy link

I have a problem with version 1.3.2.
The filters defined in ApplicationController of my application (app/controllers/application_controller.rb) are executed when accessising the list of emails.

This is strange beacuse LettersController (app/controllers/letter_opener_web/letters_controller.rb) inherits from ApplicationController defined within the gem (app/controllers/letter_opener_web/application_controller.rb).

Any idea on how to solve this issue?

Many thanks in advance.

@ciihla
Copy link

ciihla commented Jan 27, 2018

You can skip filters in ApplicationController if defined?(LetterOpenerWeb::LettersController) && is_a?(LetterOpenerWeb::LettersController)
Or fork the gem end extend class LettersController < LetterOpenerWeb::ApplicationController
That should solve your problem..

@mauro-ni
Copy link
Author

mauro-ni commented Jan 29, 2018

@ciihla at the moment I skip filters using an initializer with the following code:

Rails.application.config.to_prepare do
    begin
        LetterOpenerWeb::LettersController.skip_before_action :filter1, :filter2
    rescue NameError
        Rails.logger.info 'Gem letter_opener_web is not installed, therefore cannot be configured!'
    end
end

It could be useful to let the developer choose the behaviour through a letter_opener_web config parameter. This way one may choose between extending own application controller or not.

What do you think?

Mauro

EDIT: handle the case when the gem is not installed (eg. production env)

@mauro-ni
Copy link
Author

mauro-ni commented Feb 7, 2018

Pull request #78

@pseudomuto
Copy link
Contributor

Sorry for the delay everyone...please feel free to ping me in PRs and issues in the future so I get notified.

@pseudomuto
Copy link
Contributor

Resolved by #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants