How to convert attribute name to string?
Posted
by Acidburn2k
on Stack Overflow
See other posts from Stack Overflow
or by Acidburn2k
Published on 2010-03-28T16:42:18Z
Indexed on
2010/03/28
16:53 UTC
Read the original article
Hit count: 348
Lets say we have some basic AR model.
class User < ActiveRecord::Base
attr_accessible :firstname, :lastname, :email
end
...
some_helper_method(attrib)
...
def
Now I would like to pass someuser.firstname to helper and I would like to get both the value and the attribute name, for example:
some_helper_method(someuser.firstname)
> "firstname: Joe"
some_helper_method(someuser.lastname)
> "lastname: Doe"
© Stack Overflow or respective owner