Forum: Ruby on Rails Newbie :: multiple database

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.
D69cd9081a425b5c8b5efa6b0633135c?d=identicon&s=25 Rahul Ha (aveo)
on 2007-04-19 13:24
Hi all,

I've a three simple table,

project.resource_id   (id from resource table)


training.resource_id   (id from resource table)

 I want to display list of projects and trainings that only belong to
particular resource.

#in project Controller
def proj
    @resource =Resource.find(params[:id], :include => :projects)

So it is showing projects associated with resource, But how can show
trainings associated with resource on same page.

I was trying something like
 @train = Training.find(@params["id"])
#### in proj
But doesnot work. Do I need to create association for this?

<h1>Projects of Resource: <%= %></h1>
<table border="1">
 <td width="30%"><p align="center"><i><b>ID</b></i></td>
 <td width="20%"><p align="center"><i><b>Project name</b></i></td>
 <td width="20%"><p align="center"><i><b>Training name</b></i></td>
 <% @resource.projects.each do |project| %>
 <td><%= link_to, :action => "show", :id =>
 <td><%= %></td>
<td><%= %></td>
 <% end %>

Please help me out.

6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2007-04-19 15:21
(Received via mailing list)
@resource =Resource.find(params[:id], :include =>[:projects, :trainings]

As long as your associations are set in the models, this will work.

class Resource < ActiveRecord::base
   has_many :trainings
   has_many :projects


That will work.

Rails has an api at where this is all
You should make sure to give that a look if you have additional
This topic is locked and can not be replied to.