Database.Yml &References Not Working

database.yml &references not working

Psych is the new YAML parser which is presumably better but can't merge hash keys.

This should help
http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-2-p180-here-there-be-dragons

Ruby 1.9.2 patchlevel 180 - libyaml breaks yaml node reference

Anyway, upgrade to ruby-p290 solved the issue.

Why do some Rails projects use multiple database.yml files with different extensions (mysql, postgresql etc)?

Since database.yml should not be committed to the source code for various reasons (their .gitignore explicitly removes database.yml from the repo), maintainers tend to put .yml.template as a guide for those would fork the repo. It's not meant to be renamed but rather copied as renaming it would be removing the template.

The multiple extensions (i.e .mysql, .postgres) are just there for you to know what to copy when you use different databases.

Rails 3: DataObjects::SQLError -- How do I stop these from producing errors on *warnings*?

For the inevitable poor soul who also has to work around this issue...

The problem is that JDBC (which is what DataObjects wraps) adjusts the MySQL variable sql_mode and sets it to TRADITIONAL, which adds this behaviour to MySQL. You just need to undo that anywhere in your application before you use DataMapper (only needs to be done once).

repository(:default).adapter.execute("SET sql_mode = ''")

Since sql_mode can be a comma separated list of modes, ideally you probably want to do something smarter to just strip TRADITIONAL from the list, but the above is a quick and dirty solution.

UPDATE: It's not just the TRADITIONAL flag that causes it. It's TRADITIONAL,STRICT_ALL_TABLES and STRICT_TRANS_TABLES. I inspected what JDBC had configured and eliminated the problematic modes by trial and error. The resulting list that doesn't produce the WARNING = ERROR behaviour is:

REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_UNSIGNED_SUBTRACTION,NO_DIR_IN_CREATE,ANSI,NO_BACKSLASH_ESCAPES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

How to solve the following rails 3 error: ArgumentError (Syck is not missing constant BadAlias!)?

After searching and searching the internet, I started to look at all my YAML in my app, and I validate each file using: http://yaml-online-parser.appspot.com/, and I've got errors like:

while parsing a flow node
expected the node content, but found ':'
in "<unicode string>", line 147, column 13:
order: [:day, :month, :year]

Therefore everything was because the yaml errors. The problem is with unicode, in seems that its different on ruby 1.9.2 than in 1.8.7.

Best way to create custom config options for my Rails app?

For general application configuration that doesn't need to be stored in a database table, I like to create a config.yml file within the config directory. For your example, it might look like this:

defaults: &defaults
audiocast_uri_format: http://blablalba/blabbitybla/yadda

development:
<<: *defaults

test:
<<: *defaults

production:
<<: *defaults

This configuration file gets loaded from a custom initializer in config/initializers:

# Rails 2
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV]

# Rails 3+
APP_CONFIG = YAML.load_file(Rails.root.join('config/config.yml'))[Rails.env]

If you're using Rails 3, ensure you don't accidentally add a leading slash to your relative config path.

You can then retrieve the value using:

uri_format = APP_CONFIG['audiocast_uri_format']

See this Railscast for full details.

How to include a YAML file inside a YAML file in Ruby

I found a way to address my scenario using ERB.

I monkey patched YAML module to add two new methods

module YAML
def YAML.include file_name
require 'erb'
ERB.new(IO.read(file_name)).result
end

def YAML.load_erb file_name
YAML::load(YAML::include(file_name))
end
end

I have three YAML files.

mod1_config.yml

mod1:
age: 30
city: San Francisco

mod2_config.yml

mod2:
menu: menu1
window: window1

all_config.yml

<%= YAML::include("mod1_config.yml") %>
<%= YAML::include("mod2_config.yml") %>

Parse the yaml file using the method YAML::load_erb instead of the method YAML::load.

  config = YAML::load_erb('all_config.yml') 
config['mod1']['age'] # 30
config['mod2']['menu'] # menu1

Caveats:

  1. Does not support document merge
  2. Last include overwrites same named keys


Related Topics



Leave a reply



Submit