# Hide attributes?

**URL:** <https://www.ruby-forum.com/t/hide-attributes/94322>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/hide-attributes/94322 "2005-11-12T12:49:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/hide-attributes/94322/1 "2005-11-12T12:49:56Z")

</div>

Is there a quick and easy way to hide certain  
attributes? For example, with ‘members’, I don’t want  
the password field to show up in ‘list’. Something  
like ‘attr\_protected :password’.

thanks  
csn

* * *

Yahoo! Mail - PC Magazine Editors’ Choice 2005

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/hide-attributes/94322/2 "2005-11-12T12:49:58Z")

</div>

If you’re basing your views on the standard scaffold, you can limit  
the columns displayed by generating the list of content\_columns in the  
controller action:

```
  @content_columns = User.content_columns
  @content_columns.delete_if { |c| ["salted_password", "salt",

```

“security\_token”, “token\_expiry”].include?(c.name) }

… and then in your list.rhtml view:

\<% for column in @content\_columns %\>

\<%= column.human\_name %\>  
\<% end %\>

etc.

- james

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 29, 2005, 7:49pm UTC](https://www.ruby-forum.com/t/hide-attributes/94322/3 "2005-12-29T19:49:36Z")

</div>

james.adam wrote:

> If you’re basing your views on the standard scaffold, you can limit  
> the columns displayed by generating the list of content\_columns in the  
> controller action:
> 
> ```
> @content_columns = User.content_columns
> @content_columns.delete_if { |c| ["salted_password", "salt",
> 
> ```
> 
> “security\_token”, “token\_expiry”].include?(c.name) }

Thanks, this works great on the level of a single controller. But how  
can I implement hiding on a more global level, e.g. if I never wanted to  
show the lock\_version or created\_at fields in list tables generated by  
scaffolds?

My guess is to put this code in controllers/application.rb but what do I  
use for the object?

@content\_columns = **WHATHERE?**.content\_columns  
@content\_columns.delete\_if { |c| [“salted\_password”, “salt”,  
“security\_token”, “token\_expiry”].include?(c.name) }

Thanks for your help  
R
