Too many columns for list.rhtml to display on one page


#1

I’ve gone once through the Agile book and am now attempting my own rails
app. I’ve created a table named ‘volunteers’ with over 15 columns. The
problem is the default list.rhtml that is created with the scaffold,
shows all the columns. I only want to show 4 of them with the list
view.

Where would I start to only return a handfull of columns to the screen?
I think I do it in the view (list.rhtml - excerpted below). Does anyone
have an example that only prints out a subset of the columns in a table?

Listing volunteers

<% for column in Volunteer.content_columns %> <% end %> ............
<%= column.human_name %>

#2

Sean C. wrote:

Listing volunteers

<% for column in Volunteer.content_columns %> <% end %> ............

You can edit your model and list the columns you want to display
(anywhere after the class line):

def self.list_columns
self.columns_hash.values_at(“name”,“phone”,“address”)
end

(edit name, phone, address to be the columns you want)

Then, tweak your list.rhtml view:

<% for column in Volunteer.list_columns %>


<% end %>

Hope this helps.

Phil

<%= column.human_name %>
<%= column.human_name %>

#3

Sean C. wrote:

Listing volunteers

<% for column in Volunteer.content_columns %> <% end %> ............

Something like:

<% my_content_columns = %w{foo bar qux}.collect {|colname|
Volunteer.columns_hash[colname]} %>

<%= column.human_name %>
<% for column in my_content_columns %> <% end %> <% for volunteer in @volunteers %> <% for column in my_content_columns %> <% end %> <% end %>
<%= column.human_name %>
<%= volunteer.send(column.name) %>