[Rails] select list generated from table

Miguel Enrique Cobá Martínez m.coba.m at gmail.com
Thu Jan 26 17:57:16 GMT 2006


Craig White wrote:
> Have 2 tables - clients & case_managers
> 
> class Client < ActiveRecord::Base
>   has_one :case_manager
> end
> 
> app/views/clients/_form.html contains line...
> 
> <p><% collection_select("client", "case_manager_id", \
> case_manager.find_all, "name", "id") %></p>
> 

Maybe:

<p><% collection_select("client", "case_manager_id", \
CaseManager.find(:all), "id", "name") %></p>

supposing CaseManager is the model for your table

> and this line generates error...
> undefined local variable or method `case_manager' for
> #<#<Class:0xb7b93f84>:0xb7b93b88>
> 
> What should the collection_select statement look like for it to populate
> a pop-up select list of the names column from case_managers table?
> 
> for reference;
> 
> clients table has defined...
> id integer primary key not null
> case_manager_id not null
> foreign key (case_manager_id) references case_managers(id)
> 
> case_managers table has defined
> id integer primary key not null
> name character varying 53 not null
> no foreign keys
> 
> case_managers_clients table has defined
> client_id integer not null
> case_manager_id integer not null
> no primary key
> 
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> 



More information about the Rails mailing list