I have a line of code that is running really slow because it is generating loads of SQL statements.
<%= select 'user', 'manages_office_id' , Office.find
all).collect {|d| [ d.name + ', ' + d.organisation.name, d.id ] } %>
I have 'offices' that each belong to 'organisations' and this code is producing a dropdown of all offices (but with the organisation name attached).
The d.organisation.name is generating a seperate SQL requests for each office.
Any ideas what could be done to stop hitting the database so much?
<%= select 'user', 'manages_office_id' , Office.find

I have 'offices' that each belong to 'organisations' and this code is producing a dropdown of all offices (but with the organisation name attached).
The d.organisation.name is generating a seperate SQL requests for each office.
Any ideas what could be done to stop hitting the database so much?