How can I add a subscription to a different model than the User model (eg. Organisation, Team, etc.)?
There are plenty of reasons you want to attach a subscription to another model than the User model. Sjabloon is set up to make this easy, but involves a bit more manual work. It should ideally be done early stage.
- Rollback the migration (rails db:rollback) that adds the payment fields to the users table (add_payment_fields_to_users) or to
_accounts
/_people
(if you choose this). Find/replace:users
with whatever model you want to add it to (make sure the table name is plural!). Re-run the migration. - In
config/app_config.yml
change thepayer_class
to your new model name (eg. “Team”). - Move
include Sjabloon::Stripe::Payer
frommodel/user.rb
to your new model. - Lastly, in
app/controllers/application_controller.rb
, change thecurrent_payer
to include the “current model” for which you want to add subscriptions to (eg “current_team”). For User this is the defaultcurrent_user
that comes with Devise. You need to create a “current model” (eg.current__team
) method yourself.