Camelize database calls

I have legacy Sql Server database and Rails applications. Column names
in database are all in PascalCase (FirstName, CustomerId…).

I’m searching for an easy way to use underscore_casing in Ruby and
PascalCasing in database. I would like to write first_name in Rails
for FirstName column in database.

Just like translating Ruby in rjs templates to JavaScript cameCase
convention.

The best I found so far is a start of writing plugin:
http://code.google.com/p/rails-mssql-tools/

Any advice would be great.
Thanks,
Igor.

Check methods like…

 human_name()
 tableize()
 underscore()
 humanize()
 pluralize()
 singularize()

Check that
underscore() method… I think u are saying about this

camelize and underscore will convert a string to required casing

but I’m looking for something more general like:
ActiveRecord::Base.camelize_table_column_names = true
:slight_smile:

like existing
ActiveRecord::Base.pluralize_table_names

def ChangeTheBloodyColumnNames < ActiveRecord::Base
def self.up
rename_column :table, :FirstName, :first_name

end

def self.down
raise IrreversibleMigration, “No can do sir!”
end
end

On Dec 20, 2007 4:18 AM, Nathan E.
[email protected]
wrote:

method_name = value


Ryan B.
http://www.frozenplague.net

There is nothing that specific and generic but you can iterate through
all the attributes using meta and then do something to this effect

self.attributes.each do |method_name|
define_method(method_name.underscore)
method_name
end

define_method(method_name.underscore + “=”, value)
method_name = value
end
end

This is very much pseudocode but I assure you this is possible and not
too hard to do.

Check methods like “define_method” out for more information. Even better
look at “alias_attribute”

Whoops, the def Change… should be class Change.

On Dec 20, 2007 10:20 AM, Ryan B. [email protected] wrote:

self.attributes.each do |method_name|
too hard to do.

Ryan B.
http://www.frozenplague.net


Ryan B.
http://www.frozenplague.net

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs