Skip to content

Commit

Permalink
Add customizing pay models documentation pay-rails#59
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Feb 11, 2019
1 parent b5990b4 commit c742e40
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,36 @@ user = User.find_by(email: '[email protected]')
user.subscription.processor_subscription
```

### Customizing Pay Models

Want to add methods to `Pay::Subscription` or `Pay::Charge`? You can
define a concern and simply include it in the model when Rails loads the
code.

We'll be using the `to_prepare` method to allow our concerns to be
included every time Rails reloads the models in development as well.

```ruby
# app/models/concerns/subscription_extensions.rb
module SubscriptionExtensions
extend ActiveSupport::Concern
included do
# associations and other class level things go here
end
# instance methods and code go here
end
```ruby
# config/initializers/subscription_extensions.rb

# Re-include the SubscriptionExtensions every time Rails reloads
Rails.application.config.to_prepare do
Pay.subscription_model.include SubscriptionExtensions
end
```

## Contributors

- [Jason Charnes](https://twitter.com/jmcharnes)
Expand Down

0 comments on commit c742e40

Please sign in to comment.