I receive from the database the entire list.
#<ActiveRecord::Relation [#<Item id: 1, name: "AAA", unit_price: 10000><#Item ....] Next, I need to go through a loop or an iterator and divide the value of unit_price by 100, write the result back and display it in view.
I try this:
def index @items = Item.all @items.each{ @items[unit_price] = @items[unit_price] /100 } end In response, I get:
undefined local variable or method `unit_price '
I look in manual hashes
user = {name:"Vasya", last_name: "Petrov", age: 20} user[:name] #=> "Vasya" and try this:
def index @items = Item.all @items.each{ @items[:unit_price] = @items[:unit_price] /100 } end getting an answer
no implicit conversion of Symbol into Integer
Probably the value of @items [: unit_price], it does not consider the integer, although in the database it is ok ...
def index @items = Item.all @items.each{ @items[:unit_price] = @items[:unit_price].to_i /100 } end getting an answer
no implicit conversion of Symbol into Integer
So @ items.unit_price also tried, there is no such method unit_price
How to sort through these arrays and how to access the necessary fields?
eachworks, you would at least read the language site . - D-side