Errors when running 'Generate' in Ruby

This problem usually appears only after you have created your first application, generated the symlink for your new subdomain, built the database and then attempted to build the controllers for the project according to Knowledgebase article ID: 000232, using the:

[~/rails/first]# ./script/generate controller First list view new edit

command string. The normal result would be several lines of 'created' strings, indicating that the controllers have been successfully built.

Instead, you get several errors beginning with something like:

/usr/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 54, col 0: `production:' (ArgumentError) 
        from /usr/lib/ruby/1.8/yaml.rb:133:in `load'
        from /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:523:in `database_configuration'
        from /usr/lib/ruby/gems/1.8/gems/rails- 1.2.3/lib/initializer.rb:228:in `initialize_database'

In other cases, the error strings may begin with something like this:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:204:in `establish_connection': development database is not configured(ActiveRecord::AdapterNotSpecified) 
        from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:195:in `establish_connection'

Both of these instances are indicating that there is a problem, probably structural, with the database.yml file. This file was created by the 'rails first' command and is located in the /rails/first/config/ directory.

The database.yml file is, strictly speaking a 'yaml' file. YAML is "an international collaboration to make a data serialization language which is both human readable and computationally powerful." (follow the link for the citation) Problems occur because of one absolutely inviolable rule with yaml files; they may not use a anywhere in the document. Only spaces are allowed. PYTHON users often have problems here, because may be used within PYTHON files. The bottom line is that the database.yml file is very precisely structured and critical to Ruby operations. The combination means that a small error in the database.yml file will cause disastrous consequences in Ruby, usually meaning a complete failure to do what you expected to be done. Let's take one very obvious instance. The comment in a .yml file is indicated by a '#' at the beginning of the comment. Everything between '#' and the next line is ignored by the interpreter. Some developers habitually use a '#' in their passwords to meet password complexity requirements. A '#' in a password, username, or file name used within a .yml file will cause the interpreter to fail. Yml files are also strictly hierarchical, similar to an .xml file. What this means is that the following three structures contained within database.yml are not equivalent. The first:

development:
  adapter: mysql
  database: username_firstdev
  host: localhost
  username: username_rails
  password: password

will work properly, because the arguments of the "Nested Mapping" for "development:" are indented, indicating hierarchy.

This structure:

development:
adapter: mysql
database: username_firstdev
host: localhost
username: username_rails
password: password

will fail because the interpreter will attempt to place "adapter:" at the same level as "development:". In a world where "white space" isn't considered, these would be equivalent. In the Ruby world, they are entirely different constructs.

This structure:

development:
	adapter: mysql
	database: username_firstdev
	host: localhost
	username: username_rails
	password: password

despite looking similar to the first, will also fail because tabs are used for the argument lines instead of spaces.


Being scrupulous about the structure and syntax of your .yml files in Ruby projects will avoid many of the frustrating problems which can prevent successful deployment of your application. As programmers, we often look only at the text in a file and ignore structure, since, in our world, 'white space' usually has no meaning. In YAML-World, nothing could be further from the truth.

You should now go on to read other YAML documents. You can find a lot of helpful information at http://yaml4r.sourceforge.net/, as well as http://www.yaml.org/. The YAML Cookbook can provide invaluable structure and syntax tips.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to set up Ruby on Rails

Using Ruby On Rails on Iwebhosting.com.my:This is intended to be a brief introduction to...

What is the path to Ruby?

The path to the Ruby interpretor is:/usr/bin/ruby

How do I install my own Gems?

1) Using File Manager in your cPanel make a copy of the .bashrc file in your root directory, name...

How to add MIME type and associate it with .rhtml extension

For version eruby-1.0.5:SSH into your box.mkdir ~/erubycd ~/erubywget...

.htaccess File to Fix Ruby on Rails 404 Errors

Please create a .htaccess file inside the public folder with the following code: # General...