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? .......... <h1>Listing volunteers</h1> <table> <tr> <% for column in Volunteer.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> ............ -- Posted via http://www.ruby-forum.com/.
Philip Edelbrock
2005-Dec-30 22:33 UTC
Re: Too many columns for list.rhtml to display on one page
Sean Clark wrote:> 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? > > .......... > <h1>Listing volunteers</h1> > > <table> > <tr> > <% for column in Volunteer.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > ............ >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 %> <th><%= column.human_name %></th> <% end %> Hope this helps. Phil
Alex Young
2005-Dec-30 22:46 UTC
Re: Too many columns for list.rhtml to display on one page
Sean Clark wrote:> 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? > > .......... > <h1>Listing volunteers</h1> > > <table> > <tr> > <% for column in Volunteer.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > ............ >Something like: <% my_content_columns = %w{foo bar qux}.collect {|colname| Volunteer.columns_hash[colname]} %> <table> <tr> <% for column in my_content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <% for volunteer in @volunteers %> <tr> <% for column in my_content_columns %> <td> <%= volunteer.send(column.name) %> </td> <% end %> </tr> <% end %> </table> -- Alex
Matt.C.Wagner@wellsfargo.com
2005-Dec-31 03:27 UTC
[Rails] Too many columns for list.rhtml to display on one page
rails-bounces@lists.rubyonrails.org wrote:> Does anyone have an example that only prints out a subset of the > columns in a table? > > .......... > <h1>Listing volunteers</h1> > > <table> > <tr> > <% for column in Volunteer.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > ............Sean, I had the same need, and I solved it like this in my ''list.rhtml'': <% for column in Volunteer.content_columns.reject { |r| r.name =~ /date_added/ || r.name =~ /notes/ } %> <th><%= column.human_name %></th> <% end %> Hope this helps. Matt -- Matt C. Wagner Information Security Analyst Network Intrusion Detection Security Operations Center Corporate Information Security Wells Fargo Bank