''show'' method should be:
def show(id)
sum = Sum.find(id)
@applicants = sum.applicants
end
Then in show.rhtml view you have:
<% for each applicant in @applicants %>
<% applicant.fullname %>
<% end %>
On 6/26/06, Valen <onishvalen@rogers.com> wrote:>
>
> 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
>
> <h1>welcome</h1>
> <p>Click on a position name
> to see all of applicants.</p>
> <ul>
> <% @positions.each do |position| %>
> <li><%= link_to "#{position.position_name} ",
> :controller => "applicant",
> :action => "show",
> :id => position.id %>
> </li>
> <% end %>
> </ul>
> -----------------------
> and my question is - how to code applicant controller and show method
> not using SQL query directly.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
"Impossible is nothing."
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060627/b2cb37f6/attachment-0001.html