# HABTM problem

**URL:** <https://www.ruby-forum.com/t/habtm-problem/129667>\
**Category:** Rails\
**Created:** [February 20, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/habtm-problem/129667 "2008-02-20T15:35:45Z")\
**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 20, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/habtm-problem/129667/1 "2008-02-20T15:35:45Z")

</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|%\>  
\<%= p.collection\_select :relation\_ids, Relation.find(:all, :order =\>  
‘relation\_name ASC’), :id, :relation\_name, { :selected =\> p.relation\_ids  
}, { :multiple =\> true, :name =\> ‘p[relation\_ids][]’ } -%\>  
\<%end%\>

I am getting error undefined method name relation\_ids

how should i write the above piece of code so that the selected  
relation\_id and person\_id go into the people\_relations table.

Thank you.
