ianic
December 19, 2007, 10:47am
1
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.
ianic
December 19, 2007, 11:15am
2
Check methods like…
human_name()
tableize()
underscore()
humanize()
pluralize()
singularize()
ianic
December 19, 2007, 11:17am
3
Check that
underscore() method… I think u are saying about this
ianic
December 19, 2007, 4:50pm
4
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
like existing
ActiveRecord::Base.pluralize_table_names
ianic
December 20, 2007, 12:51am
5
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.
ianic
December 19, 2007, 6:48pm
6
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”
ianic
December 20, 2007, 12:51am
7
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.