0

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!

Cojones
  • 2,702
  • 4
  • 23
  • 36

1 Answers1

1

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
Community
  • 1
  • 1
adamliesko
  • 1,781
  • 1
  • 13
  • 21