Hello, tell me how to determine the relationship, depending on the attribute of the model? The User model has a pay_currency attribute, which can be 'real' or 'bitcoin'. There are 2 engines (Tbitcoin, Tstripe) each of which has the same payment table.
You need to find a way to create a payment from the user, send it to the desired engine automatically.
# Пример создания payments User.create(pay_currency: 'real').payments.create # => Tstripe::Payments
Sample code for ideas
class User < ActiveRecord::Base has_many :payments, ~> { where "pay_currency = 'real'" } , class_name: Tstripe::Payment, foreign_key: :uid has_many :payments, ~> { where "pay_currency = 'bitcoin'" } ,class_name: Tbitcoin::Payment, foreign_key: :uid end
In what direction to think to implement such dynamics?