What is the best way to modify this so that it only displays select columns? Coming from perl it seems natural to use a regex on the end like "if column.name =~/column1|column2/". But is there a cleaner way in ruby? <% for column in Affiliate.content_columns %> <td><%=h affiliate.send(column.name) %></td> <% end %>
i cant see exactly how you want this to be cleaner, you can go through the column list in your controller and decide which fields you want to display, then put these in a list. On 8/13/05, snacktime <snacktime-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is the best way to modify this so that it only displays select > columns? > Coming from perl it seems natural to use a regex on the end like "if > column.name =~/column1|column2/". But is there a cleaner way in ruby? > > <% for column in Affiliate.content_columns %> > <td><%=h affiliate.send(column.name) %></td> > <% end %> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> On 8/13/05, snacktime <snacktime-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > What is the best way to modify this so that it only displays select > > columns? > > Coming from perl it seems natural to use a regex on the end like "if > > column.name =~/column1|column2/". But is there a cleaner way in ruby? > > > > <% for column in Affiliate.content_columns %> > > <td><%=h affiliate.send(column.name) %></td> > > <% end %><% columns = [ :name, :title ] -%> <% for column in Affiliate.content_columns.select { |c| columns.include?(c.name.to_s) } -%> Or, define something like this in your model: class Affiliate < AR::Base def self.visible_column_names [:name, :title] end def self.visible_columns content_columns.select { |c| visible_column_names.include(c.name.to_s) } end end Then in your view: <% for column in Affiliate.visible_columns -%> -- rick http://techno-weenie.net