ankane / mailkick

Email subscriptions for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple models?

air720boarder opened this issue · comments

Is there a way to use mail kick with multiple models other than "User"?

I was about to clone the project to create this.. Seems like there should be a setting somewhere that specifies the User Model..

So it turns out this is kind of done:
https://github.com/ankane/mailkick#reference

There we read:
"Change how the user is determined

Mailkick.user_method = -> (email) { User.find_by(email: email) }"

So if you change that line in the source from:

User.find_by(email: email)

to

AnyCustomUserModel.find_by(email: email)

The trick is once that line is edited is that it will not work with previously existing 'sent' emails.
Once that line is updated, the link that is built in the emails(unsubscribe) will now be linked to the User model and you will no longer receive:
"Validation failed: User must exist"

Here is link on how to clone a local copy and then reference it:
http://stackoverflow.com/questions/1582728/forking-a-gem-for-a-rails-project

I wonder why there is a user_type field in the optout table? Was this built for future functionality, if so, what for?

Hey @air720boarder, as @valdezm stated, you can use the user_method as defined in the readme.

@valdezm, there is a user_type model since the User relationship is polymorphic.