Hi Everyone,
I have a select list drop down in my Rails application, in the form for creating a new record.
<li>Surveyor Name<span><%= f.select :surveyorperson_id, Person.all.collect { |x| [x.personname, x.id]}, {:selected => (@kase.surveyorperson_id rescue "")} %></span></li>
This is so the user can choose from a list of Surveyor's names which one they want to associate with the Case they are creating.
What I would like to do is have the company name of the Surveyor listed next to their name in brackets.
At the moment the code looks like this:
<li>Appointed Company<span><%= f.select :appointedsurveyor_id, Company.all.collect {|m| [m.companyname, m.id]}, {:selected => (@kase.appointedsurveyor_id rescue "")} %></span></li>
<li>Appointed Surveyor<span><%= f.select :surveyorperson_id, Person.all.collect { |x| [x.personname, x.id]}, {:selected => (@kase.surveyorperson_id rescue "")} %></span></li>
Is it possible to have the company that a surveyor works for outputting after their name?
The associations are as follows:
class Company < ActiveRecord::Base
has_many :kases
has_many :people
class Person < ActiveRecord::Base
has_many :kases # foreign key in join table
belongs_to :company
I have also changed to output of the company records to their names rather than their ID numbers'.
def to_s; companyname; end
Thanks in advance!
Thanks,
Danny