Manage yml configs from active admin - ruby-on-rails

I need to edit yml files from Active Admin (database.yml, memcached.yml and others).
Are there any gem to solve this problem? If no, how can it be solved? Or maybe there are any way to keep config data in database instead of yml (anything but database.yml)?

Modifying settings in yaml files that are checked into the repository doesn't sound like a good thing to do. I suggest to store settings in a datastore like a database using http://github.com/ledermann/rails-settings
See also Ruby on Rails - Storing application configuration

Related

Why use an extension on config/database.yml?

I'm inheriting a project that uses config/database.yml.sqlite and config/database.yml.psql instead of config/database.yml.
Why is this done and how should I use it?
If I just run rake db:create rails is looking for a config/database.yml. I've tried looking for a way to specify the name of the config file but no luck.
I could just ask the people I'm inheriting the code from but after a bit of googling around I see this pattern in other projects and think that it'd be nice if SO had an answer.
It is often quite normal to add database.yml to your .gitignore file, because it can contain passwords etc, and so ought to be kept out of the Git repo.
In this case, it is useful to keep an example database.yml file in the repo, showing the settings you would want for, say a Postgres database if you are going to use that, or a Sqlite database if you prefer that for your development work. Then you can get set up quickly once you've cloned the repo.
All you have to do is run:
cp config/database.yml.psql config/database.yml
then add your own passwords for your local development database into database.yml, which will then stay out of the repo and not be shared with any other developers working on the same project.
I've actually never seen that pattern. It sounds to me that those other YAML files are pre-encoded for the target database - pre-configured so to speak.
The same result could be achieved by a single YAML file with extensive documented blocks - "here is a sqlite block, here is a Postgres block", etc.

Checking in configuration files with sensitive information into code repos

What is the best strategy in regards to checking in sensitive information into git? For example, database connection credentials, api keys, etc. For rails app, is it best to add environment files to .gitignore?
Thanks.
Your best bet is to use environment variables.
Check out these two links. The second link will show you how to keep your sensitive information secure by using environment variables to store sensitive data.
Rails Environment Variables
Environment Variables in Ruby on Rails
Nope, you don't need to ignore your env files - just remove all the secrets and use config variables ibstead... you can then refer to them using ENV['varname']
This gist shows one way of doing that using SECRET_KEY_BASE as an example (but you should do it with every sensitive key you have):
https://gist.github.com/cjolly/6265302

Simultaneous use of yaml and database to store translations

I'm currently using i18n.
I'm thinking about using both YAML and DB for translations because required workflow is next: developer creates default translation in yaml file and some admin users change them.
I see next solution: somehow merge both translation with priority to DB version.
The problem is how to do this?
One of the workarounds can be importing / merging one into another. Turn on file-based translations by default in development environment and db-based in production and import translation files into database on deployment script (capistrano, etc).
Solution is next: I18n can manage chains. You need to create config/initializers/i18n_backend.rb file and put (here is Redis for example):
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(Redis.new), I18n.backend)
More info - http://railscasts.com/episodes/256-i18n-backends

Using ActiveRecord models in a gem - how to handle database config

I have several active record models in a rails app and I would like to extract these models into a gem so that I can easily use them in several web apps. The process seems pretty straight forward, except for passing along the configuration for the models. Do I:
Add the configuration yaml file to the gem, thus assuring the databases will always be the same across all apps - seems rigid, esp for testing and dev, though the databases for production will always be consistent.
Use the ActiveRecord hooks to look for a database.yml file in the config directory with the database defined? If so, which hooks should I use?
This is a stupid idea. If you have a better way to handle this, I'm all ears. I'd prefer not to copy and paste.
You should use the host rails app's database config. Your plugin or gem should contain just the database migrations, and a rake task to run them from the host rails app (e.g. myplugin:db:migrate)
If your models need some other configuration file, you should create a rake task (e.g. myplugin:install) to copy it to your host app's config directory. (This task can call the db:migrate task automatically as well.)
Why do you want to embed the database.yml file inside the gem? Each rails application should use it's own database.yml
I would put all the models into a plugin and include that in each rails application that needs the models.

Editing a YAML file inside a Rails App

I'm trying to use a yaml config file as a very simple flat file db for a small rails app. The app has a single user, so I just need a way to store a username and password. The only thing is that I'd like to be able to edit the username and password while still inside the app and not require an app restart (so I can't load the YAML file inside an initializer...).
Any ideas on how I could accomplish this? I'm not married to the idea of using YAML, so if you have a better suggestion I'm all ears!
You really are better off using a database for this sort of thing, because it's how Rails is designed to work. The Rails default database is SQLite 3, which is a high-performance, reliable single file database.
Don't fight the defaults—use the right tool for the job.
You might wanna try iye for yaml editing on the fly. No DB needed, saves directly to file! Potentially you would just need something that tracks for file changes in your rails app and reloads your yaml file.
Here is the project page for iye: https://github.com/firmafon/iye
http://rubyforge.org/projects/rbyaml
http://yaml4r.sourceforge.net/doc/
(http://www.yaml.org/)

Resources