Alias ​​or choose AS for stale data in rails application

I have a rails application that connects to an old database.

when I request db, it returns things like "userID" instead of "id" and "userName" instead of "name".

I thought it would be easy enough to write in my controllers

: select => 'userID AS id, userName AS name'

but when I do this, the fields I'm trying to rename are not returned. Other fields that I do not smooth out are returned.

Is there a better way to do this? Maybe overlaying field names in the model?

+3
source share
1 answer

Why do not you identify changes in your model?

class User < ActiveRecord::Base
  set_primary_key "userID"
  #Use alias_attribute to define your columns to ActiveRecord standards.
  alias_attribute "name", "userName"
end

.

. http://www.slideshare.net/napcs/rails-and-legacy-databases-railsconf-2009

+4

All Articles