I want to define an instance method with the same name as the DB column name in the model and refer to the column in that method.
There seem to be two methods
class Person < ApplicationRecord
def name
self[:name]
end
def name
read_attribute(:name)
end
end
In The Rails Style Guide, self [: name]
is better. Recommend
https://github.com/satour/rails-style-guide/blob/master/README-jaJA.md#read-attribute https://stackoverrun.com/ja/q/5968719
Recommended Posts