Reputation: 2960
I'm currently working on a custom shop software written in Ruby on Rails with three gift/voucher models. One is for percentage discount, one for a specific amount and one is for groups. Now it needs to be overhauled and I was thinking to create an interface, model with polymorphic relations to the old models or something similiar to add features and functionalities to all three models.
How would you approach is? I think I'd go for model with polymorphic relations. Any suggestions weclome!
Upvotes: 1
Views: 201
Reputation: 1915
You could use Modules (which might extend Concerns).
How to use concerns in Rails 4
module Giftable
extend ActiveSupport::Concern
included do
# add relationships, validations etc.
end
def some_instance_method
..
end
module ClassMethods
def some_class_method
..
end
end
end
One of the gift/voucher model.
class SimpleVoucher < ActiveRecord::Base
include Giftable
end
Upvotes: 2