I'm working on my first rails project after having gone through quite a bit of Ruby on Rails/Up and Running.
I have a model ‘Configuration’.
In the view that got scaffolded for me (I'm still back on rails version 1.2.3) I have a list.rhtml that looks like this
<table> <tr> <% for column in Configuration.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <% for configuration in @configurations %> <tr> <% for column in Configuration.content_columns %> <td><%=h configuration.send(column.name) %></td> <% end %>
[ snip ... ]
My Configuration table has many columns, and in the list view, I'd just like to show the 'important' columns. Initially in my model I defined
class Configuration < ActiveRecord::Base def self.important_columns return [ :description, :rate, :duration, :host] end end This didn't work, but I realized I'm returning strings, not objects. I modified the view to be
<% for column in Configuration.important_columns %> <td><%=h configuration.send(column) %></td> <% end %>
But I now no longer have access to human_name for the titles. How can I get access to the column objects, knowing their names?
I thought I could perhaps figure this out by myself if I could find the source code for content_columns, but I couldn’t find it, any hints on how I might have accomplished that?
TIA,
Leonard