Question

I am using devise_invitable gem in my application. If a user is already signed in the application and he clicks on the Accept Invitation link then he is redirected to devise after_sign_in_path_for. I want to change that and give the user some flash that he is signed in the application and needs to sign out before continuing. After clicking on Accept Invitation link my control goes to Users::InvitationsController#edit. But I am not able to get current_user in Invitations Controller. My routes and action is as:

  devise_for :users, controllers: { registrations: "registrations", :invitations => 'users/invitations', sessions: "sessions", confirmations: "confirmations", passwords: "passwords" }

  def edit
    Rails.logger.debug current_user.inspect
    if current_user.present?
      Rails.logger.debug "---current user---"
    else
      render :edit
    end
  end

Can some one please suggest how I can get the current user in invitations controller.

Was it helpful?

Solution

This is the line in InvitationsController that prevents current_user from being assigned:

prepend_before_filter :require_no_authentication, :only => [:edit, :update, :destroy]

Add this to your controller and current_user will be assigned:

skip_filter :require_no_authentication, :only => :edit

OTHER TIPS

For devise_invitable 1.7,

I got the invited_user by doing

invited_user = User.find_by_invitation_token(params[:invitation_token], true)

Docs: https://github.com/scambra/devise_invitable/tree/1-7-stable#find-by-invitation-token-

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top