Can't access model attributes via symbol

If I do a:

In controller: @x = User.find(:all)

In view: <% for rec in @x -%> <h1><%= rec[:username] %></h1> <% end -%>

It doesn't work. However, rec["username"] works. If I look with the breakpointer, of course all keys that ActiveRecord returns are strings. How can I access by symbol instead? (It is important so I can stay DRY ;-))

rec[:username.to_s]

would do it... just convert your symbol to a string...

Why not just:

rec.username

or if you really feel the need to use a symbol:

rec.send(:username)

but let the ActiveRecord attribute methods do their thing. :wink:

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com