Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access attributes from inside a model

I have a model named item that has a column named price. I assumed that price would be stored as an instance variable inside item but the method

def price
  @price
end

Returns nothing. So my question is how can I access and override the value price pulled from the database from inside my model.

like image 888
ChadTheDev Avatar asked Dec 24 '16 16:12

ChadTheDev


1 Answers

You use according to the Rails guides

def price
  self[:price]
end
like image 191
Eyeslandic Avatar answered Sep 28 '22 02:09

Eyeslandic