[英]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.