Forum: Ruby on Rails Strange behavior of Source.column_names

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.
05c3f39db309047f28628a223a757bec?d=identicon&s=25 Hans Marmolin (marmolin)
on 2009-03-01 18:16
(Received via mailing list)
I have a class named Source and a controller named SourceController
etc.

When I use Source.column_names in the view all names except names
ending in _id is listed, although according to the documentation all
names should be listed

When I  use Source.column_names in the source controller it lists
correctly all names also the ones ending in id.

When I first call  Source.column_names in the controller then it lists
all names also in the view when I use  Source.column_names.

Is this a bug in rails ?
Is the calls Source reserved ?
Has anyone  had the same problem ?
Is there anyway to solve this problem in a better way than the fisx I
use  by first calling  Source.column_names in the controller ?
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-03-02 10:34
(Received via mailing list)
i really can't answer your questions regarding why this happens, but
for the HOW_TO part i'd suggest to just do it like this:

# controller:
@columns = Source.column_names

# view:
<%= @columns %>

this respects MVC.
This topic is locked and can not be replied to.