Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:40:25+00:00 2026-06-10T20:40:25+00:00

I have a lot of static preferences for one entity. Do I need to

  • 0

I have a lot of static preferences for one entity. Do I need to store them in database table? Or I could use YAML configuration file, with approximate structure:

name: "Lights"
descriptions: ""
items: 
  title: "Fog lighs"
  description: "Should be used in foggy environment only!"

  title: "Xenon"
  description: "6500K"

name "Safety"
description: "Safety systems"
items:
  title: "Airbag"
  description: ""

  title: "ABS"
  description: "bla bla bla"

with ruby/object model markup. Can this be done with a nesting structure like in my example above?

Can somebody tell, if it is a good practice to do so? I don’t want to use database, because these settings would be pretty much static, with low probability of need to change anything.

If it is possible, I would also like to know how to implement translation (i18n) for the elements of the structure (names and titles). I don’t know where to put it in this particular situation.

Or I should use an entirely different approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:40:27+00:00Added an answer on June 10, 2026 at 8:40 pm

    You can of course use YAML in your rails app the same way you would from any ruby app:

    require 'yaml'
    things = YAML::load(open("my_things.yml"))
    

    For translation just use the existing Rails I18n framework.

    For example, given the classes:

    class Thing
      attr_accessor :title, :description
    end
    
    class Lights < Thing
    end
    
    class Safety < Thing
    end
    

    And the following YAML data file:

    ---
    - !ruby/object:Lights
      title: "Fog lights"
      description: "Should be used in foggy environments only!"
    - !ruby/object:Lights
      title: "Xenon"
      description: "6500K"
    - !ruby/object:Safety
      title: "Airbag"
    - !ruby/object:Safety
      title: "ABS"
      description: "bla bla bla"
    

    You can add the translation in config/locale/things.nb.yml:

    nb:
      lights:
        fog_lights:
          title: "Tåkelys"
          description: "Kun til bruk i tåke!"
        xenon:
          title: "Xenon"
          description: "6500K"
      safety:
        airbag:
          title: "Kollisjonspute"
        abs:
          title: "ABS"
          description: "bla bla bla"
    

    Similar for other languages, of course. Now let’s implement a method to describe a thing:

    class Thing
      def describe
        key = title.parameterize
        thing = self.class.to_s.downcase
        translated_title = I18n::t("#{thing}.#{key}.title")
        if description
          translated_description = I18n::t("#{thing}.#{key}.description")
        else
          translated_description = ""
        end
        "#{translated_title}: #{translated_description}"
      end
    end
    

    Assuming the current language is Norwegian, you can now do:

    things.each do |thing|
      puts thing.describe
    end
    

    and get:

    Tåkelys: Kun til bruk i tåke!
    Xenon: 6500K
    Kollisjonspute: 
    ABS: bla bla bla
    

    Notice you may either drop the description tags from the original YAML file, or have them as default fallbacks if there is no translation available.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of static IF statements that I need to use to
I have a database holding a lot of static data for my current application.
I have a lot of static JSON text content indexed in a database. Some
I have a requirement to use date picker in my applicaiton. I have lot
In my project I have a lot of email addresses on static sites. Is
I have a music related ASP.NET web site which caches a lot of static
I have a Makefile which uses a lot of static files, for example: /mystaticpath/somepath/official_gpl_package-0.1.2.tar.gz
How can I create (seed) a lot of static data in Entity Framework? By
I have a high traffic website with a lot of static content. It is
I have a project which consist of a lot of static HTML and js

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.