# RE: restricting list output (newbie)

**URL:** <https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953>\
**Category:** Rails\
**Created:** [November 27, 2005, 6:53pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953 "2005-11-27T18:53:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 27, 2005, 6:53pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/1 "2005-11-27T18:53:17Z")

</div>

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:

 \<% for author in @authors %\> \<% end %\>

| First Name | Last Name |
| --- | --- |
| \<%=author.first\_name %\> | \<%=author.last\_name %\> |

Don’t fear the HTML 🙂

---

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 27, 2005, 8:42pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/2 "2005-11-27T20:42:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 27, 2005, 9:30pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/3 "2005-11-27T21:30:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 27, 2005, 9:51pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/4 "2005-11-27T21:51:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 27, 2005, 10:07pm UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/5 "2005-11-27T22:07:33Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![HOGANBP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@HOGANBP](https://www.ruby-forum.com/u/HOGANBP)\
**Post date:** [November 28, 2005, 1:29am UTC](https://www.ruby-forum.com/t/re-restricting-list-output-newbie/48953/6 "2005-11-28T01:29:18Z")

</div>

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
