How to solve an error in Heroku's config/database.yml file “mapping values are not allowed in this context”

I'm deploying an app to Heroku and it's mostly fine but for this error

mapping values are not allowed in this context at line 22 column 13 (Psych::SyntaxError)

The line they are referring to is line 22 of the database.yml file that Heroku itself is writing over my own file, as per standard practice.

Jumping into heroku run bash and taking a look at the file in question:


require 'cgi'
require 'uri'

  uri = URI.parse(ENV["DATABASE_URL"])
rescue URI::InvalidURIError
  raise "Invalid DATABASE_URL"

raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"]

def attribute(name, value, force_string = false)
  if value
    value_string =
      if force_string
        '"' + value + '"'
    "#{name}: #{value_string}"

adapter = uri.scheme
adapter = "postgresql" if adapter == "postgres"

database = (uri.path || "").split("/")[1]

username = uri.user
password = uri.password

host =
port = uri.port

params = CGI.parse(uri.query || "")


<%= ENV["RAILS_ENV"] || ENV["RACK_ENV"] %>:
  <%= attribute "adapter",  adapter %>
  <%= attribute "database", database %>
  <%= attribute "username", username %>
  <%= attribute "password", password, true %>
  <%= attribute "host",     host %>
  <%= attribute "port",     port %>

<% params.each do |key, value| %>
  <%= key %>: <%= value.first %>
<% end %>

Line 22 is

    "#{name}: #{value_string}"

Any suggestions as to how to resolve this problem?


Okay after some more research I have worked out the problem. Sigh.

On my local machine I am loading my database configuration as follows:

dbconfig = YAML::load("config","database.yml")))

but because the yml file that Heroku generates is actually an ERB file in disguise, I need to parse it first.

Changing the above line to:

dbconfig = YAML.load("config","database.yml"))).result)

works a treat.

Need Your Help

C#: Try-catch every line of code without individual try-catch blocks

c# try-catch

I do not currently have this issue, but you never know, and thought experiments are always fun.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.