devise_invitable icon indicating copy to clipboard operation
devise_invitable copied to clipboard

Halting callback chain may cause unexpected app behavior

Open j15e opened this issue 7 years ago • 0 comments

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.locale setup (which result in the flash message not being in the proper I18n.locale depending 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_action rather than prepend_before_action.

I will be happy to provide a pull request for a solution, based on community feedback.

j15e avatar Feb 10 '18 21:02 j15e