I have a Listing model that I know I don't want to display a few of the
columns, but I don't want to hard-code the columns that I do want
either.
Is there a way to exclude certain columns?
This is what I have:
<% for column in Listing.content_columns %>
<th><%= column.human_name %></th>
This is roughly what I want (in midnight pseudo-code):
<% for column in Listing.content_columns[exclude: column_1, column_2] %>
<th><%= column.human_name %></th>
I have a Listing model that I know I don't want to display a few of the
columns, but I don't want to hard-code the columns that I do want
either.
Is there a way to exclude certain columns?
This is what I have:
<% for column in Listing.content_columns %>
<th><%= column.human_name %></th>
This is roughly what I want (in midnight pseudo-code):
<% for column in Listing.content_columns[exclude: column_1, column_2] %>
<th><%= column.human_name %></th>
do-able?
Absolutely!
I'd say what's missing is a content_columns_names method (at least I
can't find one). It would look something like this:
class ActiveRecord::Base
def self.content_column_human_names
content_columns.map {|c| c.human_name }
end
end
You could put that into a plugin, or just roll it into your
application code (as below). In either case, it's probably best to
put the array operation in the controller, which is a better place for
dynamic determination of names you don't want.
So the whole thing might look like this (untested, and partially
pseudo-code):