Is this the way to do it, through? Or should I try something like Sphinx for these type of searches (which I am thinking of using anyway).
- Rilindo
Which essentially returns the same thing as Book.column_names.collect
(&:name)
On Dec 18, 3:07 am, Kip Cole <kipco...@gmail.com> wrote:
> Rilindo, the class method "columns" called on an ActiveRecord class is what you want. Let's say you have a table called "books" with corresponding model Book. Then:
>
> Book.columns will return an array of column objects of the columns in the table. Not so useful for a select list.
>
> Book.columns.collect{|x| x.name} will return an array of just the column names. But this will contain the "id" column and maybe other foreign keys you don't want in a select list. Therefore:
>
> Book.columns.collect{|x| x.name}.reject{|x| x == 'id' || x.match(/_id\Z/)} might be closer to what you want,
>
> Cheers, --Kip
>
> Topic: A Describe Method / Pull list of Fields
> Rilindo Foster <rili...@gmail.com> Dec 17 11:17PM -0500
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
M
> --
>
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
>
--
Rilindo Foster
AOL Instant Messenger: rilindo
Google Talk: ril...@gmail.com
Web Site: http://www.monzell.com
Primary: ril...@me.com
Secondary: ril...@gmail.com
"Rich bachelors should be heavily taxed. It is not fair that some men
should be happier than others. -- Oscar Wilde