Marcos Icaza Marcos Icaza - 1 month ago 6x
Ruby Question

How to get only the value from a Rails query

I want to get the integer value from this query in rails.'GXZ44', store_id:'44555222')

On my controller, I am trying to select the amount sold from my inventory and I want to get only the integer value from the
column. When I run that query, I get:

< Inventory id: nil, amt_sold: 175.0>

How can I just get the 175.0 value as a integer to be able to do arithmetic operations on it?


try this:

my_int =  Inventory.where(item_ID:'GXZ44', store_id:'44555222').first.amt_sold