Chris Klimek wrote in post #1059910:> I have a function that displays all depts and related info from other
> tables in my Department model, such as:
>
> def dept_and_hospital
> "#{name} (#{floor.building.hospital.name})"
> end
>
> ... which is used in my view, like:
>
> <p>
> <%= f.label :department_id %><br />
> <%= collection_select(:device, :department_id, Department.all(),
> :id, :dept_and_hospital, :prompt => ''Select
Department'') %>
> </p>
First, get Department.all() out of your view. It doesn''t belong there.
It''s not the responsibly of the view to load it''s own data.
Put that in
the controller where it belongs.
> How do I sort the display names by the hospital name (which is a few
> "tables away" in the db schema), and then by the department name.
>
> The relationship in the db is as follows:
> department-->floor-->building--> hospital.
Given that it sounds like your list of results is small enough to fetch
them all into memory, then you can sort them in memory using Ruby, I''ll
leave that as an exercise for you.
Sorting arrays:
http://bit.ly/Kt6sI9
--
Posted via http://www.ruby-forum.com/.
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.