If you ment you want to create the slug when creating an invite:
I've encountered the same problem.
the command i use to invite a user:
User.invite!(email: "example@email.com", name: "John John")
the problem is that for some reason the should_generate_new_friendly_id?
is not called in this proccess.
my solution was to write a method to create the user slug
def slug_me!
new_slug = [name.parameterize].join("-")
if User.where(slug: new_slug).present? #check if the is a user with that slug already
new_slug = [name.parameterize, User.last.id+1].join("-")
end
update_column(:slug, new_slug)
end
(in my app the new_slag will be unique. not sure about your app. you might need to change [name.parameterize, User.last.id+1].join("-")
to something else that will fit your needs)
and override the invite!
method that devise uses:
def invite!
super
slug_me! if should_generate_new_friendly_id?
end
(i've added if should_generate_new_friendly_id?
so it wont create a slug if you invite the same person more then once)
in this case should_generate_new_friendly_id?
will return true
because slug
is nil
so slug.blank?
will return true
its might not be the best solution, but it works for me.
(and im still looking for a better solution)