devise_invitable
devise_invitable copied to clipboard
Halting callback chain may cause unexpected app behavior
Problem description
Devise::InvitationsController may cause unexpected behaviors if your application is using callbacks to setup important context information to the application.
Examples :
- Skipping the setup of debugging context (ex. setting requests informations)
- Skipping
I18n.localesetup (which result in the flash message not being in the properI18n.localedepending of the worker previous state)
Cause description
Application before_action callbacks are skipped when devise_invitable halt the chain by rendering or redirecting inside its own callbacks :
https://github.com/scambra/devise_invitable/blob/080dd0bf78efd0ad74080dbe23214bfc243c7778/app/controllers/devise/invitations_controller.rb#L91-L104
And it does so because they are inserted before the application callbacks using prepend_before_action :
https://github.com/scambra/devise_invitable/blob/080dd0bf78efd0ad74080dbe23214bfc243c7778/app/controllers/devise/invitations_controller.rb#L2-L5
Suggestions
- Keep those methods to avoid repeating code, but move the calls into the actions themselve, therefore avoiding to halt the application callbacks chain.
- Use
before_actionrather thanprepend_before_action.
I will be happy to provide a pull request for a solution, based on community feedback.