2013-10-30 92 views
2

我生產含有消息散列「消息」的屬性是這樣的:插入一個屬性在軌哈希

message = Message.create_from_mail_message(mail, @current_sender_email, expires_at, public, message_type) 

現在我想附加屬性「access_key」添加到這個散列「消息」的問題是此屬性不在消息模型中,但在收據中。任何想法如何做到這一點。

眼下信息散返回我:

 access_key = Reciept.access_key 

在此先感謝:

{"active":1,"body":"","created_at":"2013-10-30T10:49:41Z","creator_id":6,"expires_at":"2013-11-29T10:49:41Z","id":25,"message_type_id":1,"public":0,"reply_to":null,"slug":"fa2fd66f-7e32-4e3f-898b-8412c676a0ff","subject":"2af03892533ffb43\ufffdh\ufffdf\ufffdS+9<\b&\u0017\ufffd\u0016/\ufffd","updated_at":"2013-10-30T10:49:41Z"} 

「access_key」 可以被檢索。

回答

1
message.merge!{access_key: Reciept.access_key} 
4

試試這個:

message.merge!('access_key' => Reciept.access_key) 
6

你應該像信息散與值合併access_key:

message.merge( 「access_key」=> Reciept.access_key)

0

斯塔爾說:

message.merge(:access_key=>Reciept.access_key) 

我希望我能幫助你。