i have a table with 5 columns, but i only want to display 3 columns with "list.rhtml". what´s the best way to do this?
patrick wrote:> i have a table with 5 columns, but i only want to display 3 columns with > "list.rhtml". > > what''s the best way to do this?If the list.rhtml is the standard generated scaffolding, try outputting the three columns directly (via item.colname) instead of using the for loop. -- Posted via http://www.ruby-forum.com/.
Huh? :) Oh you''re probably referring to scaffolding.
Well, you could just do it by hand.
Say your table looks like this:
Authors
========= id
first_name
last_name
email
Controller:
def list
@authors = Author.find(:all)
# or you might have paginate stuff there instead
end
View:
Just write this code by hand:
<table id="authors_list">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<% for author in @authors %>
<tr>
<td><%=author.first_name %></td>
<td><%=author.last_name %></td>
</tr>
<% end %>
</table>
Don''t fear the HTML :)
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of patrick k
Sent: Sunday, November 27, 2005 6:40 AM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] restricting list output (newbie)
i have a table with 5 columns, but i only want to display 3 columns with
"list.rhtml".
what´s the best way to do this?
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
i tried your solution, but it didn´t seem "clean" to me.
i thought of something like (referring to the example):
@authors =
Author.find(''first_name'',''last_name'')
of course, this code is not correct. but there should be an easier way than
modifying the HTML by hand, right?
patrick
> Huh? :) Oh you''re probably referring to scaffolding.
>
> Well, you could just do it by hand.
>
>
> Say your table looks like this:
>
> Authors
> =========> id
> first_name
> last_name
> email
>
>
> Controller:
>
> def list
> @authors = Author.find(:all)
> # or you might have paginate stuff there instead
> end
>
> View:
>
> Just write this code by hand:
>
> <table id="authors_list">
> <tr>
> <th>First Name</th>
> <th>Last Name</th>
> </tr>
> <% for author in @authors %>
> <tr>
> <td><%=author.first_name %></td>
> <td><%=author.last_name %></td>
> </tr>
> <% end %>
> </table>
>
>
> Don''t fear the HTML :)
>
>
> -----Original Message-----
> From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of patrick k
> Sent: Sunday, November 27, 2005 6:40 AM
> To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> Subject: [Rails] restricting list output (newbie)
>
>
> i have a table with 5 columns, but i only want to display 3 columns with
> "list.rhtml".
>
> what´s the best way to do this?
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
patrick k wrote:> i tried your solution, but it didn´t seem "clean" to me. > > i thought of something like (referring to the example): > @authors = Author.find(''first_name'',''last_name'') > > of course, this code is not correct. but there should be an easier way than > modifying the HTML by hand, right? >No, generated HTML is just to get you started. You should expect to replace it completely. Justin> >>Huh? :) Oh you''re probably referring to scaffolding. >> >>Well, you could just do it by hand. >> >> >>Say your table looks like this: >> >>Authors >>=========>>id >>first_name >>last_name >>email >> >> >>Controller: >> >>def list >> @authors = Author.find(:all) >> # or you might have paginate stuff there instead >>end >> >>View: >> >>Just write this code by hand: >> >><table id="authors_list"> >><tr> >> <th>First Name</th> >> <th>Last Name</th> >></tr> >><% for author in @authors %> >><tr> >> <td><%=author.first_name %></td> >> <td><%=author.last_name %></td> >></tr> >><% end %> >></table> >> >> >>Don''t fear the HTML :) >> >> >>-----Original Message----- >>From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of patrick k >>Sent: Sunday, November 27, 2005 6:40 AM >>To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>Subject: [Rails] restricting list output (newbie) >> >> >>i have a table with 5 columns, but i only want to display 3 columns with >>"list.rhtml". >> >>what´s the best way to do this? >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
define a subset of Author.content_columns in your controller and then
use this in your scaffold loop instead of Author.content_columns
directly:
desired_columns = [''first_name'',
''last_name'']
@content_columns = Author.content_columns.select { |c|
desired_columns.include?(c.name) }
- james
On 11/27/05, Justin Forder
<justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org>
wrote:> patrick k wrote:
> > i tried your solution, but it didn´t seem "clean" to me.
> >
> > i thought of something like (referring to the example):
> > @authors =
Author.find(''first_name'',''last_name'')
> >
> > of course, this code is not correct. but there should be an easier way
than
> > modifying the HTML by hand, right?
> >
>
> No, generated HTML is just to get you started. You should expect to
> replace it completely.
>
> Justin
>
> >
> >>Huh? :) Oh you''re probably referring to scaffolding.
> >>
> >>Well, you could just do it by hand.
> >>
> >>
> >>Say your table looks like this:
> >>
> >>Authors
> >>=========> >>id
> >>first_name
> >>last_name
> >>email
> >>
> >>
> >>Controller:
> >>
> >>def list
> >> @authors = Author.find(:all)
> >> # or you might have paginate stuff there instead
> >>end
> >>
> >>View:
> >>
> >>Just write this code by hand:
> >>
> >><table id="authors_list">
> >><tr>
> >> <th>First Name</th>
> >> <th>Last Name</th>
> >></tr>
> >><% for author in @authors %>
> >><tr>
> >> <td><%=author.first_name %></td>
> >> <td><%=author.last_name %></td>
> >></tr>
> >><% end %>
> >></table>
> >>
> >>
> >>Don''t fear the HTML :)
> >>
> >>
> >>-----Original Message-----
> >>From:
rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>
>>[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of patrick k
> >>Sent: Sunday, November 27, 2005 6:40 AM
> >>To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> >>Subject: [Rails] restricting list output (newbie)
> >>
> >>
> >>i have a table with 5 columns, but i only want to display 3 columns
with
> >>"list.rhtml".
> >>
> >>what´s the best way to do this?
> >>
> >>_______________________________________________
> >>Rails mailing list
> >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> >>http://lists.rubyonrails.org/mailman/listinfo/rails
> >>_______________________________________________
> >>Rails mailing list
> >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> >>http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
nice. tried it and ... worked. thanks. looks like this is a more appropriate way to handle the problem compared with changing the HTML-code. this should be part of the tuturial, wiki ... (maybe it already is, but i didn´t find it).> define a subset of Author.content_columns in your controller and then > use this in your scaffold loop instead of Author.content_columns > directly: > > desired_columns = [''first_name'', ''last_name''] > @content_columns = Author.content_columns.select { |c| > desired_columns.include?(c.name) } > > > - james > > On 11/27/05, Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org> wrote: >> patrick k wrote: >>> i tried your solution, but it didn´t seem "clean" to me. >>> >>> i thought of something like (referring to the example): >>> @authors = Author.find(''first_name'',''last_name'') >>> >>> of course, this code is not correct. but there should be an easier way than >>> modifying the HTML by hand, right? >>> >> >> No, generated HTML is just to get you started. You should expect to >> replace it completely. >> >> Justin >> >>> >>>> Huh? :) Oh you''re probably referring to scaffolding. >>>> >>>> Well, you could just do it by hand. >>>> >>>> >>>> Say your table looks like this: >>>> >>>> Authors >>>> =========>>>> id >>>> first_name >>>> last_name >>>> email >>>> >>>> >>>> Controller: >>>> >>>> def list >>>> @authors = Author.find(:all) >>>> # or you might have paginate stuff there instead >>>> end >>>> >>>> View: >>>> >>>> Just write this code by hand: >>>> >>>> <table id="authors_list"> >>>> <tr> >>>> <th>First Name</th> >>>> <th>Last Name</th> >>>> </tr> >>>> <% for author in @authors %> >>>> <tr> >>>> <td><%=author.first_name %></td> >>>> <td><%=author.last_name %></td> >>>> </tr> >>>> <% end %> >>>> </table> >>>> >>>> >>>> Don''t fear the HTML :) >>>> >>>> >>>> -----Original Message----- >>>> From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of patrick k >>>> Sent: Sunday, November 27, 2005 6:40 AM >>>> To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> Subject: [Rails] restricting list output (newbie) >>>> >>>> >>>> i have a table with 5 columns, but i only want to display 3 columns with >>>> "list.rhtml". >>>> >>>> what´s the best way to do this? >>>> >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi: I am a newbie too so this answer may be junk. However, here goes.... (all the techno geniuses please be nice, I am attempting to be helpful). @authors = Author.find(:select => ''first_name, last_name,etc) etc. However, the other answer you were given is perfectly "clean" in my opinion and certainly gives more control. bruce On 27-Nov-05, at 12:41 PM, patrick k wrote:> i tried your solution, but it didn´t seem "clean" to me. > > i thought of something like (referring to the example): > @authors = Author.find(''first_name'',''last_name'') > > of course, this code is not correct. but there should be an easier > way than > modifying the HTML by hand, right? > > patrick > > > >> Huh? :) Oh you''re probably referring to scaffolding. >> >> Well, you could just do it by hand. >> >> >> Say your table looks like this: >> >> Authors >> =========>> id >> first_name >> last_name >> email >> >> >> Controller: >> >> def list >> @authors = Author.find(:all) >> # or you might have paginate stuff there instead >> end >> >> View: >> >> Just write this code by hand: >> >> <table id="authors_list"> >> <tr> >> <th>First Name</th> >> <th>Last Name</th> >> </tr> >> <% for author in @authors %> >> <tr> >> <td><%=author.first_name %></td> >> <td><%=author.last_name %></td> >> </tr> >> <% end %> >> </table> >> >> >> Don''t fear the HTML :) >> >> >> -----Original Message----- >> From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of patrick k >> Sent: Sunday, November 27, 2005 6:40 AM >> To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Subject: [Rails] restricting list output (newbie) >> >> >> i have a table with 5 columns, but i only want to display 3 >> columns with >> "list.rhtml". >> >> what´s the best way to do this? >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails