Search code examples
ruby-on-railsrubysyntax-errorscaffolding

Ruby on Rails Scaffold with number as a db header


I'm trying to generate a scaffolding in RoR with numbers as headings:

rails g scaffold company user_id:integer 2010:text

It runs the scaffolding correctly, but when I try to do a migration I get the following error:

syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END

Am I just doing something wrong or can't one name a heading a number?


Solution

  • Such migration violates ruby syntax at first. But even for pure SQL you can't provide heading starts with number. For example, you can find description in Postgres docs:

    SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($).