# HABTM problem

**URL:** <https://discuss.rubyonrails.org/t/habtm-problem/25193>\
**Category:** rubyonrails-talk\
**Created:** [February 20, 2008, 2:35pm UTC](https://discuss.rubyonrails.org/t/habtm-problem/25193 "2008-02-20T14:35:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 20, 2008, 2:35pm UTC](https://discuss.rubyonrails.org/t/habtm-problem/25193/1 "2008-02-20T14:35:45Z")

</div>

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

class Relation \< ActiveRecord::Base &nbsp;&nbsp;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]' } -%\>\</td\> \<%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.
