0

I have been following Ryan Boland's Rails multitenancy tutorial, but have run into a snag with devise_invitable.

I create a new account and user/account owner on a chosen subdomain (mysubdomain.lvh.me:3000), from which I can send a user invitation just fine. I open the invitation link in an incognito Chrome session to ensure I am not logged in or have any current session. Upon clicking on the invitation link, I am redirected to the sign in page (mysubdomain.lvh.me:3000/users/sign_in) and see a flash notice: "The invitation token provided is not valid!"

Related to this one:

Rails 4 devise_invitable invitation token invalid

Community
  • 1
  • 1
Rafa Ramírez
  • 161
  • 1
  • 9

1 Answers1

0

[SOLVED]

In case anyone has the same issue, override the invitations controller and change the Tenant with Apartment:

# app/controllers/users/invitations_controller.rb
class Users::InvitationsController < Devise::InvitationsController
  private
    def resource_from_invitation_token
      Apartment::Tenant.switch!(request.subdomain) //ADD THIS BABY!
      unless params[:invitation_token] && 
      self.resource = resource_class.find_by_invitation_token(params[:invitation_token], true)
        set_flash_message(:alert, :invitation_token_invalid)
        redirect_to after_sign_out_path_for(resource_name)
      end
    end
end

Remember to update your routes also, like this:

# config/routes.rb
devise_for :users, :controllers => { :invitations => 'users/invitations' }
Rafa Ramírez
  • 161
  • 1
  • 9