2

In my Rails app I need to maintain too many default texts. For example, I have a Hotel model. When someone creates a hotel, some default email templates, default sms templates get created automatically for that hotel. Currently I am maintaining them inside a Constants modules and access them like:

 Constants::DEFAULT_RESERVATION_EMAIL_TEMPLATE

 Constants::DEFAULT_RESERVATION_SMS_TEMPLATE

etc.

I wonder if there any other convenient and efficient ways to maintain those default texts as it seems Constants module is going huge in each days. I am thinking like I can manage them in a yaml file so that it does not affect on memory and I can read from the yaml file when necessary.

Muntasim
  • 6,689
  • 3
  • 46
  • 69

1 Answers1

3

I would use the normal i18n yml files for that. You can manage multiple languages through yml files. And you can easily change the content.

But you also can use a database for your backend.

Following links could give you an idea:

Community
  • 1
  • 1
Matthias
  • 4,355
  • 2
  • 25
  • 34
  • I use globalize3 to store translated contents. btw you prefer to store models default data in yaml files instead of using Constants? – Muntasim Sep 16 '13 at 16:41
  • 1
    Yes I do. I translate all "static" and "default" stuff with yaml files. The file format is quite easy, and you can give it to your translators and they can translate the content directly. With constants you always have to copy the new translations in your code base. Yaml files can be kept separately. I think through this separation your code will be cleaner - like separate css and js files :).. – Matthias Sep 16 '13 at 16:52
  • Thanks for supporting me :), I am going to get rid of my constants though it contains some complex hash. Not sure enough how much complex it will be to fit those hashes in yaml file. – Muntasim Sep 16 '13 at 16:58
  • I think you can convert complex hashes easily to yaml files. Maybe this could help you also: http://www.yaml.org/YAML_for_ruby.html If I am right, yaml is just an other "syntax" or "format" for ruby hashes. You an always interpret a ruby hash through yaml format and visa versa. – Matthias Sep 16 '13 at 17:04