Search code examples
ruby-on-railsdevisedevise-invitable

Cannot accept invitation from devise_invitable


I'm working on a small app, using Devise with two models: Coach and Athlete (a coach can have several athletes). Now I'm trying to achieve an invitation system, using the DeviseInvitable gem.

Everything seems fine: when a coach click on the new_athlete_invitation_path, an athlete is created, with an invitation_token and a coach_id. But if I try to accept the invitation, following the path from my routes, and the invitation_token, then I got redirected with the following message:

Started GET "/athlete/invitation/accept?invitation_token=536dc1aee8faef0842a21f6c90fa68121e6c3858c5697215b8282474875fdff0" for 127.0.0.1 at 2019-03-19 11:34:34 +0100
Processing by Athletes::InvitationsController#edit as HTML
  Parameters: {"invitation_token"=>"536dc1aee8faef0842a21f6c90fa68121e6c3858c5697215b8282474875fdff0"}
  Athlete Load (1.0ms)  SELECT  "athletes".* FROM "athletes" WHERE "athletes"."invitation_token" = $1 ORDER BY "athletes"."id" ASC LIMIT $2  [["invitation_token", "4316731df92b3e5d369c17971b9db96aea1d33de8741ae5602f6065ef8174a5b"], ["LIMIT", 1]]
  ↳ /home/soykje/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Redirected to http://localhost:3000/
Filter chain halted as :resource_from_invitation_token rendered or redirected
Completed 302 Found in 8ms (ActiveRecord: 3.0ms)

I can't figure out the reason of this problem... Would it be related to my two-models configuration? Did I miss something?

Thx in advance for your help!


NB: From my Gemfile:

ruby '2.5.3'
gem 'rails', '~> 5.2.2'
gem 'devise', '~> 4.6', '>= 4.6.1'
gem 'devise_invitable', '~> 2.0'

Solution

  • Okay that was my mistake: I was trying to accept the invitation using the unencrypted token. Just by adding LetterOpener I was able to confirm the invitation, using the correct generated link. Always use the generated link!