Josh S. wrote:
Wes G. wrote:
Anybody know of a way to alias a column in ActiveRecord such that you
could reference it via a different symbol in your view for view purposes?
Like my column is named X but I want to display it as Y and maybe I have
an accessor named Y set up on the model so that when I “call” Y from the
view (and controller?) I’m actually manipulating the column X?
Use Ruby’s ‘alias’ feature.
alias :y :x
alias :y= :x=
Make sure you alias after the :x methods are defined, because a later
‘def x’ will create a new :x method and :y will point to the old :x.
this is probably well and all for an experianced programmer to
understand. But I’m a total noob, so how would you for instance alias a
column name namned “login” to the alias “foo” in a table namned “users”
Tried something like this… and it does not work:
class User < ActiveRecord::Base
foo = value
alias :foo :login
alias :foo= :login=
so… how should the define methods look like?