A.2 ActiveRecord
(A single record)
A.2.1 All column names
You get a method for every column in the table; for example, if you have retrieved an individual record from the Contact
table, you can call .first_name
, .last_name
, etc, on it.
This means that every ActiveRecord
object will have methods .id
, .created_at
, and .updated_at
, since every table has those columns.
A.2.2 Any other instance methods you define in the class
It’s often helpful to define your own instance methods in the model file; for example, you might want to define a method .full_name
:
class Contact < ApplicationRecord
def full_name
return self.first_name + " " + self.last_name
end
end
You would then be able to call .full_name
anywhere in the application that you wind up with an individual Contact
object.