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.

有帮助吗?

解决方案

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

其他提示

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-

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top