Reputation: 6612
I want to prevent going to the database if possible. This is a rarely changing list of cities and states that will be populated in the beginning of the project and used by the application to format and find verify those locations.
So far from my research:
config/initializers
yml file
database but cache it (I don't want to hit the database)
Kind of confused so want the best method for performance and convention.
Upvotes: 2
Views: 763
Reputation: 2873
I would suggest going one of two ways:
create a ruby object by hand, which contains the data and can answer the relevant questions:
class Cities
def self.data
{
1: 'New York',
2: 'Boston'
}
end
def self.find_name_by_id(id)
data[id]
end
end
This means doing a bit more by hand and not having everything "free" that ActiveRecord normally gives you. Or...
Upvotes: 2