1

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!

2 Answers 2

7
:select => "created_on AS date"

alternatively define a method

def date
  read_attribute(:created_on)
end
Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.