我目前正在设法为发票/账单提取信息。 在发票上,我要表明总价是多少。 程序和营地;物品、价格和价格。 因此,我希望最终能够看到:
Consult [date] [total_price]
Procedure_name [price] [qty]
Procedure_name [price] [qty]
Consult [date] [total_price]
Procedure_name [price] [qty]
etc...
所有这些信息均可通过数据库获取,但希望将信息作为单独的副本予以节省。 如果用户改变某些程序的价格,发票信息仍然正确。 我认为,通过在发票表中将数据编成一个栏(协商数据)并加以节省,这样做。
我的模式:
class Invoice < ActiveRecord::Base
...stuff...
serialize :consult_data
...
end
这是我从形式上获得的(1项咨询和3项程序):
{"commit"=>"Save draft", "authenticity_token"=>"MZ1OiOCtj/BOu73eVVkolZBWoN8Fy1skHqKgih7Sbzw=", "id"=>"113", "consults"=>[{"consult_date"=>"2010-02-20", "consult_problem"=>"ABC", "procedures"=>[{"name"=>"asdasdasd", "price"=>"2.0", "qty"=>"1"}, {"name"=>"AAAnd another one", "price"=>"45.0", "qty"=>"4"}, {"name"=>"asdasdasd", "price"=>"2.0", "qty"=>"1"}], "consult_id"=>"1"}]}
我的拯救行动:
def add_to_invoice
@invoice = @current_practice.invoices.find_by_id(params[:id])
@invoice.consult_data=params[:consults]
if @invoice.save
render :text => "I think it worked"
else
render :text => "I don t think it worked "
end
end
数据库除外,如果我看一看奥利斯群岛的条目,我可以发现那里有:
consult_data: "---
- !map:HashWithIndifferentAccess
consult_da..."
(---The question---) But I can t seam to get back my data. I tried defining a variable to the consult_data attribute and then doing "variable.consult_problem" or "variable[:consult_problem]" (also tried looping) but it only throws no-method-errors back at me.
我如何利用数据库的数据,将其重新定位为能够使用的信息库?
非常感谢你们的任何帮助!