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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Check methods like.. human_name() tableize() underscore() humanize() pluralize() singularize() -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Check that underscore() method... I think u are saying about this -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Esquenazi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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" > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Whoops, the def Change... should be class Change. On Dec 20, 2007 10:20 AM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 Esquenazi < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > 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" > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > > > -- > Ryan Bigg > http://www.frozenplague.net-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---