Hello everyone, first post to the list and a relative newbie to Rails
development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I
would
kick the tires on Rails to see if it can speed up development for
internal
applications. Anyway, I am running into a problem that is just driving
me
crazy and everything I read on the net doesn’t seem to help. I was
hoping
someone here might have had the same problem and be able to point me in
the
right direction.
Database Schema:
table employees
id
name
table projects
id
name
table project_roles
id
name
table project_members
id
employee_id
project_id
role_id
I then have the following ActiveRecord objects:
class Employee < ActiveRecord::Base
has_and_belongs_to_many :project_members, :join_table =>
“project_members”, :class_name => “ProjectMember”
end
class Project < ActiveRecord::Base
has_and_belongs_to_many :project_members, :join_table =>
“project_members”, :class_name => “ProjectMember”
end
class ProjectRole < ActiveRecord::Base
has_and_belongs_to_many :project_members, :join_table =>
“project_members”, :class_name => “ProjectMember”
end
class ProjectMember < ActiveRecord::Base
belongs_to :project
belongs_to :employee
belongs_to :project_role
set_table_name “project_members”
end
The next thing I want to do is to display a multi-select list box, on
the
project form, and display all of the employees that when selected will
add
the proper entries into the project_members table. I would be happy to
write
a method that gets called on submission and transforms the @params into
the
appropriate ActiveRecord requests, but I cannot get the list to display
with
collection_select no matter what I try.
Can someone point me in the right direction? Am I using the
has_and_belongs_to_many relationship wrong? Is it useless to try to get
this
kind of a relationship to show up using collection_select? Is there some
other parameters that I need to use that I am not? Is there a better
pattern
for these type of relationships with regards to integrating them into
the
MVC paradigm?
Any help would be appreciated as I am Googled out!
Keith