EastsideDev
EastsideDev

Reputation: 6659

Accessing an object's hash key in Rails

Rails 3.2

I am using the Rails console. I have the following object: payment:

=> #<Invoice id: "14848", from: "Acme Processing", to_id: "Jones Electric", total: "$68.77", paid_at: "2017-01-19">

I can access to_id, by doing:

payment.to_id

and total:

payment.total

How do I get the value for Invoice id?

Upvotes: 0

Views: 373

Answers (2)

Zzz
Zzz

Reputation: 1703

Seems invoice has relationship with payment, just do

payment.invoice.id

Upvotes: 0

Optimus Pette
Optimus Pette

Reputation: 3400

access the values using payment[:to_id] and payment[:total] . Get more information about ruby Hashes here.

Upvotes: 1

Related Questions