scambra / devise_invitable

An invitation strategy for devise
MIT License
2.63k stars 551 forks source link

undefined method `invitation_token=' for nil:NilClass #707

Open wernerlaude opened 7 years ago

wernerlaude commented 7 years ago

Thanks for your gem. Following your instruction I do not succeed...

Rails 5, devise_invitable (1.7.1) After click on accept in the maiI get:

undefined method `invitation_token=' for nil:NilClass

Log: Started GET "/user/invitation/accept?invitation_token=5op8v6szEmixSUWWS1by" for 127.0.0.1 at 2017-03-24 14:19:56 +0100 Processing by Devise::InvitationsController#edit as HTML Parameters: {"invitation_token"=>"5op8v6szEmixSUWWS1by"} User Load (0.3ms) SELECT users.* FROM users WHERE users.invitation_token = '80a2621c39981dc1808c8fed94e9e34babd23c89147aca6e87f6e76b11d85529' ORDER BY users.id ASC LIMIT 1 Completed 500 Internal Server Error in 39ms (ActiveRecord: 3.5ms)

NoMethodError - undefined method invitation_token=' for nil:NilClass: devise_invitable (1.7.1) app/controllers/devise/invitations_controller.rb:48:inedit'

Can you help me to make that work? Greetings

scambra commented 7 years ago

There is before_action loading resource, and I see it looks for user by invitation token, that before_action redirects if no user is found and display error, so I don't understand why resource.invitation_token = ... is failing with nil exception, I can't reproduce it.

Can you try next line in rails console?

User.find_by_invitation_token('5op8v6szEmixSUWWS1by', true)

wernerlaude commented 7 years ago

Hi Sergio..

Thanks for taking care.

my Url: http://localhost:3000/user/invitation/accept?invitation_token=opaymFVm-xxTCUy4zvQP http://localhost:3000/user/invitation/accept?invitation_token=opaymFVm-xxTCUy4zvQP

Console:

User.find_by_invitation_token('opaymFVm-xxTCUy4zvQP',true) User Load (0.4ms) SELECT users.* FROM users WHERE users.invitation_token = '8009cd6b8ea7c2606a3480e297bb54b12739fd74d0501a4696f04921a35090dd' ORDER BY users.id ASC LIMIT 1 => #<User id: 10, first_name: "", last_name: "", email: "mail@icloud.com", created_at: "2017-03-28 07:13:44", updated_at: "2017-03-28 07:13:44", locale: "de", privacy: 0, mailme: 0, contact: 0, admin: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, invitation_token: "8009cd6b8ea7c2606a3480e297bb54b12739fd74d0501a4696...", invitation_created_at: "2017-03-28 07:13:44", invitation_sent_at: "2017-03-28 07:13:44", invitation_accepted_at: nil, invitation_limit: nil, invited_by_id: 3, invited_by_type: nil>

Db Invitation token: 8009cd6b8ea7c2606a3480e297bb54b12739fd74d0501a4696f04921a35090dd

Browser

NoMethodError at /user/invitation/accept

und

efined method `invitation_token=' for nil:NilClass

Am 27.03.2017 um 13:33 schrieb Sergio Cambra notifications@github.com:

There is before_action loading resource, and I see it looks for user by invitation token, that before_action redirects if no user is found and display error, so I don't understand why resource.invitation_token = ... is failing with nil exception, I can't reproduce it.

Can you try next line in rails console?

User.find_by_invitation_token('5op8v6szEmixSUWWS1by', true)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/scambra/devise_invitable/issues/707#issuecomment-289427539, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC5hVL4PmS982FB_fLrzlwOOnU-7Tg7ks5rp56VgaJpZM4MoQJv.

Werner Laude - Ruby on Rails/WebDevelopment - München mail@laude.biz mailto:mail@laude.biz | +49 178 135 34 39 <tel:+49 178 135 34 39> | webagentur-laude.de http://www.webagentur-laude.de/

scambra commented 7 years ago

Are you using 1.7.1 or git version?

wernerlaude commented 7 years ago

Am 28.03.2017 um 14:46 schrieb Sergio Cambra notifications@github.com:

Are you using 1.7.1 or git version?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/scambra/devise_invitable/issues/707#issuecomment-289758162, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC5hRS-DRQmnPUrKfd7KbfY0YTgIidaks5rqQErgaJpZM4MoQJv.

devise (4.2.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 5.1) responders warden (~> 1.2.3) devise_invitable (1.7.1) actionmailer (>= 4.1.0) devise (>= 4.0.0)

Werner Laude - Ruby on Rails/WebDevelopment - München mail@laude.biz mailto:mail@laude.biz | +49 178 135 34 39 <tel:+49 178 135 34 39> | webagentur-laude.de http://www.webagentur-laude.de/

scambra commented 7 years ago

Are you logged in with different user when trying to accept invitation? You can try with 1.7.2, which has a fix to sign out before accepting invitation, I don't know if it may be related. I just released it.

wernerlaude commented 7 years ago

Thanks.. I will check that tomorrow..

I send the mail looged in, then log out.

See the mail (letter_opener) in a different tab of the browser.

Greetings

Am 28.03.2017 um 14:57 schrieb Sergio Cambra notifications@github.com:

Are you logged in with different user when trying to accept invitation? You can try with 1.7.2, which has a fix to sign out before accepting invitation, I don't know if it may be related. I just released it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/scambra/devise_invitable/issues/707#issuecomment-289760882, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC5hSA_pjd63X3ZUOrBXNHdKHR8ky-_ks5rqQOlgaJpZM4MoQJv.

Werner Laude - Ruby on Rails/WebDevelopment - München mail@laude.biz mailto:mail@laude.biz | +49 178 135 34 39 <tel:+49 178 135 34 39> | webagentur-laude.de http://www.webagentur-laude.de/

scambra commented 7 years ago

I don't think 1.7.2 will make any difference if you do those steps, but you can try it just in case I missed something.

Also, you could edit devise/invitations_controller.rb and debug self.resource value. I would add debugging lines at the end of resource_from_invitation_token and beginning of edit method