Я использую одного таблицы наследования успешно, как так:Rails 4 STI наследование
class Transaction < ActiveRecord::Base
belongs_to :order
end
class Purchase < Transaction
end
class Refund < Transaction
end
сокращенная/упрощена PurchaseController выглядит следующим образом:
class PurchaseController < TransactionController
def new
@transaction = @order.purchases.new(type: type)
end
def create
@transaction = @order.purchases.new secure_params
if @transaction.save
redirect_to @order
else
render :new
end
end
end
сокращенная/упрощенная модель покупки выглядит следующим образом :
class Purchase < Transaction
attr_accessor :cc_number, :cc_expiry, :cc_csv
end
То, что я пытаюсь сделать есть различные варианты покупки, например покупка наличных денег & покупка чека. Проблема в том, что я не уверен, как назвать модель для этой вариации.
Например:
class Cash < Purchase
attr_accessor :receipt_no
end
class CashController < TransactionController
def new
# This will use the Purchase.rb model so that's no good because I need the Cash.rb model attributes
@transaction = @order.purchases.new(type: type)
# This gives me the following error:
# ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: Purchase is not a subclass of Cash
@transaction = Cash.new(type: 'Purchase', order: @order.id)
end
end
серьезные дежавю здесь. – sevenseacat
@sevenseacat, yep не смог его решить. – EasyCo