[英]How to create a string from active record model attributes names and values separated by a separator |?
我有一个称为Student的ActiveRecord模型,并且Student.first具有以下属性:
reg_no: "ABC001",school_fees: 10000.0,transaction_date: "2017-08-19"
我想将其转换为:
reg_no=ABC001|school_fees=10000.0|transaction_date=2017-08-19
并将其分配给变量以在该变量中执行加密和解密。 我怎么能得到这个结果?
尝试这个:
student = Student.first
student.attributes.map { |key, value| "#{key}=#{value}" }.join('|')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.