Thx for the responses which helped resolve my problem/question. Just want to close this out in case it helps others in the future.
Turns out I had been getting an error trying to reference my parent data element (patients.lname) as it was being passed in an array of results, rather than as a single result. In my view controller I had:
@visit = Visit.all(:select => "visits.id, visits.visittype, visits.visitdate, events.patient_id, patients.lname",
:conditions => ["visits.id = ?",params[:id] ],
:joins => "INNER JOIN events on events.id = visits.event_id INNER JOIN patients on patients.id = events.patient_id" )
In my view I had (this was giving me an invalid reference as I was doing a find all above):
Editing visit for patient :
# should be
Below is the improved (and simpler) version where I find the specific record I need (basically replacing find all with find first):
@visit = Visit.find(:first, :select => "visits.id, visits.visittype, visits.visitdate, events.patient_id, patients.lname",
:conditions => ["visits.id = ?",params[:id] ],
:joins => "INNER JOIN events on events.id = visits.event_id INNER JOIN patients on patients.id = events.patient_id" )
And in the view:
<% form_for(@visit, :builder => LabelFormBuilder) do |f| %>
<%= f.error_messages %>
Name: <%= @visit.lname %>
<%= f.text_field :visittype %>
<%= f.date_select :visitdate %>
<%= f.submit 'Update' %>
<% end %>
Sometimes it's hard to see the wood for the trees! Hope this helps someone else.