Forum: Ruby on Rails Single table lookups

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.
Craig W. (Guest)
on 2006-05-30 20:50
(Received via mailing list)
I'm struggling with a single table type (self) lookup.

my 'personnel' model has a supervisor_id and is_supervisor column.

The supervisor's select list is created by
  @supv = Personnel.find(:all,
   :conditions => ["is_supervisor = true"],
   :order => 'last_name')

in my personnel model, I have the following...

  def supervisor
    if Personnel.find_by_id(self.supervisor_id) == nil then

where 'suwholename' is an aggregate value of the first, middle, last

The following view code produces a select list of supervisors...

  <%= options = [['Select', '']] + @supv.collect {
     |supv| [supv.suwholename,] }
     select 'personnel', 'supervisor_id', options %></TD>

but I have 2 problems...

1. If there is no supervisor_id, I get an error...
   PGError: ERROR:  invalid input syntax for integer: ""
   : SELECT * FROM personnels WHERE (personnels."id" = '' )  LIMIT 1

2. When I have a supervisor_id, it doesn't come up as 'selected' in the
select list.

I have struggled for a while with this and can't seem to make any

This topic is locked and can not be replied to.