Преобразование другого приложения из Rails 2 в Rails 3 - в одном из моих представлений у меня есть этот код:
<%fields_for "order[commission_attributes][]", commission do |f|%>
Это зависит от действия контроллера ниже:
def edit
@order = Order.find(params[:id],:include=>[{:orderitems=>:item_schedules}, :memberids ],:order=>"orderitems.updated_at DESC")
@active_order_iems = []
@inactive_order_items = []
@order.orderitems.each do |oi|
oi_active = nil
oi.item_schedules.each do |is|
if (is.end_date > Date.today)
oi_active =true
break
end
end
@active_order_iems << oi if !oi_active.nil?
@inactive_order_items << oi if oi_active.nil?
end
@commissions = @order.commissions.find(:all)
@ordertypes = Ordertype.find(:all, :order=>"description")
@salesreps = Salesrep.find(:all, :order=>"fullname")
@customers = Customer.find(:all, :order=>"company_name")
@memberids = Memberid.find_all_by_customer_id(@order.customer_id)
@products = Product.find(:all, :include=>[:items],:order=>["products.description"])
@partners = Partner.find(:all, :order=>"company_name")
end
def get_reps
@salesreps = Salesrep.find(:all,:order=>"fullname")
@commission = Commission.new
render :partial=>'commission'
end
В моей модели 'order' у меня есть это:
def commission_attributes=(commission_attributes)
commission_attributes.each do |attributes|
if attributes[:id].blank?
commissions.build(attributes)
else
commission = commissions.detect{|t| t.id == attributes[:id].to_i}
commission.attributes = attributes
end
end
end
Это работает в рельсах 2, однако в рельсах 3 я получаю ошибку ниже:
@order[commission_attributes]' is not allowed as an instance variable name
Я не могу понять, в чем проблема или как обойти эту проблему ... любая помощь очень ценится.
Andrew