Forum: Ruby on Rails Collection_select with a mix of AR models and non AR models

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Damaris F. (Guest)
on 2007-03-21 00:32
Hi you all,

Having into account the following:

<%= collection_select("page", "subjects" , @subjects, "id", "name") %>

and that "Page" is an AR model with an attr. accesor called "subjects",
array composed by non AR model objects ("Subject" is a model
representing a file), my question is:
I can get all my @subjects from my file but, how can I set the id and
name? Is it enough to add a "def id" and "def name" methods in my non-AR
model in order to my view get these att. right? Becuase if I have to use
"select" I can not provide any value at all (I mean, the id and name),
can I?

This topic is locked and can not be replied to.