views:

139

answers:

2

What if I want to refer to a column of an ActiveRecord object by a different name? for example, I might call:

@posts = Posts.find(:all, :select => "created_on")

But instead of referring to @posts["created_on"], I'd like to refer to it as @posts["date"]. What would you recommend?

Thanks!

+6  A: 
:select => "created_on AS date"

alternatively define a method

def date
  read_attribute(:created_on)
end
Ben Hughes
+4  A: 

Already answered in your previous question, but here we go:

class Posts
  alias_method :date, :created_on
end

or simply

class Posts
  alias date created_on
end
Lars Haugseth