Forum: Ruby on Rails help... why can't Iuse data from two tables in the same view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nick Horrigan (Guest)
on 2006-02-06 23:29
(Received via mailing list)

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

Nick Horrigan
E: removed_email_address@domain.invalid
T: 01572 725454
M: 07917 464756

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.
Craig W. (Guest)
on 2006-02-06 23:47
(Received via mailing list)
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


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

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

I hope this helps

David M. (Guest)
on 2006-02-07 00:08
(Received via mailing list)
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:

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

Then, in your view:

@jobs.each do
  @people.each do
    ...(do cool stuff here)

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


Dave M.
This topic is locked and can not be replied to.