I have three tables and is not allowed to change data scheme:
CREATE TABLE applicants
(
id
int(10) unsigned NOT NULL auto_increment,
fullname
varchar(60) NOT NULL default ‘’,
address
varchar(60) NOT NULL default ‘’,
PRIMARY KEY (id
)
) ;
CREATE TABLE positions
(
id
int(10) unsigned NOT NULL auto_increment,
position_name
varchar(30) NOT NULL default ‘’,
KEY id
(id
)
) ;
CREATE TABLE sums
(
id
int(11) NOT NULL auto_increment,
applicants_id
int(10) NOT NULL,
positions_id
int(10) NOT NULL,
PRIMARY KEY (id
)
) ;
I installed:
class Sum < ActiveRecord::Base
has_many :applicants
has_many :positions
end
class Applicant < ActiveRecord::Base
belongs_to :sum
end
class Position < ActiveRecord::Base
belongs_to :sum
end
At first I want to list all positions and then having clicked on it - to
receive all applicants with this position.
class WelcomeController < ApplicationController
def index
@positions = Position.find(:all)
end
end
welcome
Click on a position name to see all of applicants.
-
<% @positions.each do |position| %>
- <%= link_to "#{position.position_name} ", :controller => "applicant", :action => "show", :id => position.id %> <% end %>