My DB tables and field names are in CamelCase. Is it possible to convert those names into snake_case on a fly? To make model methods look pretty?
The app is JRubyOnRails 3.0 / MSSQL DB / ActiveRecord-JDBC-adapter.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@arkadiy,as a matter of fact, I was looking into this just this very day.
For table names, we of course have the
set_table_namemethod:For things like primary keys, we have
set_primary_key:And it should be possible to alias funky, legacy column names to something more rails-friendly with
alias_attribute:One key thing to keep in mind is to watch out for any column names that are ruby or rails keywords or magic field names.
Rails appears to have all that metaprogramming goodness to allow you to work around legacy db table names and columns. You may wish to have a read of Jonathan Hui’s blog post on “Ruby on Rails 3 Model Working with Legacy Database”. And you might want to have a look at the safe_attributes gem.