Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I put a list of static data in Ruby on Rails?

I have a static string array of Cities, States, Categories, etc that is accessed by my application in various places. Where should I put this? In a yml file someplace or a rb file in the lib directory?

Thanks!

like image 203
Goalie Avatar asked Jan 27 '26 14:01

Goalie


1 Answers

See this so question

Basically, put constants in /config/initializers in a .rb file.


EDIT:

So this is not really constant data since "once a couple of months" the info will change. In that case you should put the info in the database and cache it. The caching will prevent round trips to the database and you can expire the cache when you need to update the info.

like image 63
Dty Avatar answered Jan 29 '26 04:01

Dty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!