Help... why can't Iuse data from two tables in the same view

David

I’ve having exactly the same problem here and can’t find a solution -
have you had any joy?

Nick Horrigan
ROL
E: [email protected]
T: 01572 725454
M: 07917 464756
W: www.rol.co.uk

This email and any files transmitted with it are confidential, may be
legally privileged and are intended solely for the use of the addressee.
If you have received this email in error you are requested to contact
the sender immediately, and not to disclose or make use of this
information. Although rol operates an active anti-virus policy, the
organisation accepts no liability for any damage caused by any virus
transmitted by this email, including any attachments. The views
contained in this email are those of the author and not necessarily
those of rol.

On Mon, 2006-02-06 at 21:29 +0000, Nick Horrigan wrote:

David

I’ve having exactly the same problem here and can’t find a solution -
have you had any joy?


I am working on this at the moment…

What has worked for me…

in myfile.rhtml

<%= this_controller.field_name %>
<%= this_controller.another_controller.field_name %>

and in

this_controller.rb

def myfile
@this_controller This_controller.find(params[:id])
@another_controller AnotherController.find(:all)
end

and also, you must set your has/belongs to/ etc. in the models

I hope this helps

Craig

Assume you want to render a view linking people and jobs together, for
some hypothetical application. You’ve got two tables, ‘people’ and
‘jobs’, that you want to drag info from for this one form.

In your controller:

jobs_controller.rb

def link_people_to_jobs
@jobs = Job.find(:all)
@people = Person.find(:all)

end

Then, in your view:

<%
@jobs.each do
|job|
@people.each do
|person|
…(do cool stuff here)
end
end
%>

Note that you should define @jobs and @people in your controller,
not try to define them in your view.

Regards

Dave M.