1
我有2种型号:accepts_nested_attributes_for虚拟属性
class Invoice < ActiveRecord::Base
has_many :invoice_items
accepts_nested_attributes_for :invoice_items, :allow_destroy => true
end
class InvoiceItem < ActiveRecord::Base
attr_accessor :encryption_key
belongs_to :invoice
end
的发票项目的列进行加密和我使用来自一个会话的加密密钥。我不想将此密钥存储在服务器或任何其他模型中。
从控制器:
params[:invoice][:invoice_items_attributes].each_value {
|v| v.merge!(:encryption_key => session['access_key'])
}
@invoice = Invoice.new(params[:invoice])
这在创建发票时把钥匙插进的属性列表不错,但它是那么不传递到InvoiceItems模型...
如何任何指针得到这个工作将是伟大的。