This is my first attempt at AJAX and I seem to be having a bit of problem. Here is what I have code-wise. In a eda_officer/new.rhtml file I have the call:
In the eda_officer/eda_officer_controller I have:
<td class="td-label" align="right"> Select an Officer</td>
<td><%= text_field_with_auto_complete :officer, :particulars %></td>
and in the eda_officer/_officers.rhtml partial I have
@officers = Voters.find_by_sql (["select concat(v.id, ' - ', v.lastname, ', ', v.firstname) as particulars from voters v left join residence r on (v.residence_id=r.id) where v.lastname like ?", '%' + params[:officer][:particulars].downcase + '%' ], :order => 'lastname ASC')
render :partial => 'officers'
Now this was my first experiment (which failed and that is why I experiment ;) just to see what kind of result would be returned. While I need the name/address information to cue the user what I really need to capture is the voter id so I can save it. If someone can give me some guidance in this area it would be appreciated.
<% for officer in @officers do -%>
<div class="name"><%=h officer.particulars %></div>
<span class="informal"><%=h officer.particulars %></span>
<% end -%>