Make after invite / accept path work like Devise Analogs #240

Merged
merged 3 commits into from Oct 10, 2012

Projects

None yet

3 participants

@mwear

With Devise proper you can easily customize after_sign_in_path_for, after_sign_out_path_for, etc by overriding the respective methods in ApplicationController. With devise_invitable the only way to override after_invite_path_for and after_accept_path_for is to override Devise::InvitationsController. I moved the methods out of the InvitationsController and into the Helpers module which is included in ActionController::Base so these methods can be easily overridden in ApplicationController like the analogous methods in Devise proper. I also added some tests in tests/functional/controller_helpers_test.rb.

If this feature is accepted, users can temporarily patch the current version of devise_invitable to respect definitions for after_invite/accept_path_for in ApplicationController by sticking the following in an initializer:

#make invitable's path functions overridable in application controller
[:after_invite_path_for, :after_accept_path_for].each do |method|
  Devise::InvitationsController.send(:remove_method, method) if ApplicationController.method_defined? method
end
@scambra scambra merged commit ada9eae into scambra:master Oct 10, 2012

1 check failed

Details default The Travis build failed
@webandy

Hello. I'm using devise_invitable 1.1.4 and verified that this commit ada9eae is present. I have admin resources inviting user resources. If I override after_invite_path_for in my application controller it isn't executed. Looking at Devise::InvitationsController#create it looks like the respond_with resource portion is executing because I'm redirected in the browser to user_url. It also seems like the resource might be wrong (user instead of admin), but I'm more interested in getting the override in ApplicationController working. Any suggestions? Thanks.

# in my application's ApplicationController
def after_invite_path_for(resource)
  admin_index_path
end
@webandy

I was able to override the action in my own Users::InvitationsController as @matchematics mentioned, but not in the applications's ApplicationController. So for me it doesn't appear that this issue was fixed. Can it be re-opened?

class Users::InvitationsController < Devise::InvitationsController
  def after_invite_path_for(resource)
    # resource is wrong, resource.is_a?(Admin) should be true
    admin_index_path
  end
end
@scambra
Owner

Do you have a failing test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment