Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting an attribute to hash in rails

I am producing a hash "message" containing Message attributes like this:

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

Now I want to add an additional attribute "access_key" to this hash "message" problem is this attribute is not in Message model but in Receipt. Any idea about how to do this.

Right now message hash returns me this :

{"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" can be retrieve by:

     access_key = Reciept.access_key

Thanks in advance.

like image 252
user2936044 Avatar asked Nov 21 '25 16:11

user2936044


2 Answers

You should merge the access_key with value in message hash like:

message.merge!("access_key" => Reciept.access_key)

like image 93
sunil Avatar answered Nov 23 '25 05:11

sunil


Try this:

message.merge!('access_key' => Reciept.access_key)
like image 32
user2503775 Avatar answered Nov 23 '25 07:11

user2503775