# HABTM and multiple select

**URL:** <https://www.ruby-forum.com/t/habtm-and-multiple-select/129455>\
**Category:** Rails\
**Created:** [February 18, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/habtm-and-multiple-select/129455 "2008-02-18T19:46:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 18, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/habtm-and-multiple-select/129455/1 "2008-02-18T19:46:54Z")

</div>

Hello,  
I have two tables “people” and “relations”  
Following are the models  
class Person \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :relations

class Relation \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :people

I want to select multiple relations and when i say  
Person.create(params[:person]) in controller  
the relation ids and and id of person should be stored in  
people\_relation table.

Here is the form for person.  
\<%form\_for (:person,:url=\>{:action =\>“create”},:html =\> { :multipart =\>  
true })do |p|%\>  
Relation:  
\<%=p.select(“id”,Relation.find(:all).collect{|rel|[rel.relation\_name,rel.id]},  
{:prompt=\>"-Select a Relation"},{:multiple=\>true})%\>  
\<%end%\>

Please tell me what do i need to do  
Thank you
