Forum: Ruby on Rails hide attributes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
http://mail.yahoo.com
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 james.adam (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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 %>
      <th><%= column.human_name %></th>
  <% end %>

etc.

- james
Ccf3683102f671121ed61551d4bdf957?d=identicon&s=25 Roland Siebelink (Guest)
on 2005-12-29 19:49
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
This topic is locked and can not be replied to.