-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting Undefined method error when using different invite use cases #832
Comments
Can you post the line or method where you get the error? |
Sure, in my implementation the methods are called "invite_new_user!" and "invite_existing_user!". I did change the name of the methods in the model and everything else that was required such as the mail templates, etc.
Thanks in advance! |
You have created class methods and try to call instance methods. I don't know if you have added methods to TeamUser or User, I'm guessing you added them to user, but those methods in wiki expect email attribute, so I don't know if they are suitable for your use case. Probably you can use instance invite! method after setting user.invitation_instructions: def create_new_team_user(user, role, is_new_user)
new_team_user = TeamUser.new
new_team_user.id = user.id
new_team_user.role = role
if new_team_user.save
if is_new_user
user.invitation_instructions = :new_user_invitation_instructions
else
user.invitation_instructions = :existing_user_invitation_instructions
end
user.invite!
else
puts new_user_program_team.errors.full_messages
end
end I'm not sure if it would work for existing users, as they can keep only one invitation token, so inviting them to another team user would break previous invitation. Also, you could add devise to TeamUser, so you can call new_team_user.invite! for existing users and user.invite! for new users. For example: def create_new_team_user(user, role, is_new_user)
new_team_user = TeamUser.new
new_team_user.id = user.id
new_team_user.role = role
if new_team_user.save
if is_new_user
user.invite!
else
new_team_user.invite!
end
else
puts new_user_program_team.errors.full_messages
end
end |
I used the first example provided but unfortunately, it didn't work. The email was sent which is good but with the default invite template not with new_user_invitation_instructions or existing_user_invitation_instructions. For this last example, "user" is the object that has the email, new_team_user is only the link between a group and a user so sending emails to this is not possible. |
For last example, you could add an email method to TeamUser which returns user.email If you want to use first example, can you add some debug info to your mailer class, so you can check if invitation_instructions is set |
I've followed this article from the wiki(Customizing for different Invite use cases). I did setup everything exactly as the documentation says, but when I get to call the invite_guest! method I get "undefined method 'invite_guest!' for #User:0x00007f11c2cdec60". The same happens for 'invite_friend!'
I am creating the user prior to sending the email, so when I call the method I do
user.invite_guest!
, theuser
already has the email and all its information, I have verified this in the console several times. By doinguser.invite!
everything works fine, the problem is only with the added methods(invite_guest!
andinvite_friend!
)If I do
User.invite_guest!(email: "ebc@email.com")
in the console, the email is sent and the error does not show. The error only happens when doing the mentioned above.Any ideas on why this is happening? Am I doing something wrong?
The text was updated successfully, but these errors were encountered: