我传递这些参数到控制器:为什么执行属性赋值的顺序失败?
{
"utf8" => "✓",
"authenticity_token" => "ersjaJ4/ieZelVifP/YpBHTJtiQ53HgO5KYjEdW0BlQ=",
"transaction" => {
"use_balance" => "1",
"traces_attributes" => {
"trace_ids" => ["6"],
"6" => {
"amount" => "12.0",
"charge_id" => "6"
}
},
"positive_balance" => "12",
"property_id" => "2",
"community_id" => "1"
},
"commit" => "Save Payment",
"community_id" => "1",
"property_id" => "2"
}
的controller#create
则:
@payment = Transaction.new(params[:transaction])
那么交易模式:
belongs_to :property
belongs_to :community
attr_accessible :positive_balance
def traces_attributes=(params)
#INSIDE HERE THE VALUES OF
#params[:trace_ids] => ['6'] OK
#BUT
#self.possitive_balance => "" **NOT OK**
#self.property_id => nil **NOT OK**
end
我的假设是traces_attribute=
是positive_balance=
前执行和property_id
我可以改变它吗? 这是为什么失败?
是的,我明白这一点。 关键是possitive_balance确实可以通过traces_attributes =来访问,因为这个attr在事务内部,并且在哈希中你可以看到possitive_balance在事务内部。 这就是为什么即时通讯使用自己而不是参数 – 2011-06-01 22:01:29