# Multiple rows in a model

**URL:** <https://www.ruby-forum.com/t/multiple-rows-in-a-model/161313>\
**Category:** Rails\
**Created:** [February 25, 2009, 11:54am UTC](https://www.ruby-forum.com/t/multiple-rows-in-a-model/161313 "2009-02-25T11:54:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmswarna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rmswarna](https://www.ruby-forum.com/u/rmswarna)\
**Post date:** [February 25, 2009, 11:54am UTC](https://www.ruby-forum.com/t/multiple-rows-in-a-model/161313/1 "2009-02-25T11:54:33Z")

</div>

Hi,

I am new to rails. Any support from your side would be very helpful.

I have two models one named Child.rb and the other named  
Filtersetting.rb

The general idea is one user can have many children and one child can  
have one Filtersetting.

Hence i have done with the User model. Now while adding child to the  
user, I need to add many child at a single hit and the Filtersetting for  
that child at the same time.

The controller code is as follows,

class ChildrenController \< ApplicationController

layout ‘standard’

def index  
parent\_id = session[:user].id  
@children = Child.find(:all, :conditions =\> [“parent\_id = ?”,  
parent\_id])  
if @children.empty?  
flash[:notice] = “No child set”  
end  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @children }  
end  
end

def new  
@child = Child.new  
@level= Level.find(:all)  
@cat = Filtercategory.find(:all)  
@filter = Filtersetting.new  
respond\_to do |format|  
format.html # new.html.erb  
format.xml { render :xml =\> @child }  
end  
end

def create  
@child = Child.new(params[:child])  
@child.parent\_id = session[:user].id  
childname = @child.childname  
@filter = Filtersetting.new(params[:filtersetting])  
@filter.childname = childname  
if @filter.levelid == 1  
@filter.levelname = “Elementary School”  
end  
if @filter.levelid == 2  
@filter.levelname = “Middle School”  
else  
@filter.levelname = “High School”  
end

```
respond_to do |format|
  if @child.save
    @filter.childid = @child.id
    @filter.save
    flash[:notice] = 'Child was successfully created.'
   format.html { redirect_to(@child) }
  else
    format.html { render :action => "new" }
    format.xml { render :xml => @child.errors, :status =>

```

:unprocessable\_entity }  
end  
end  
end

end

end

The view code is as follows,

\<%= start\_form\_tag :action =\> ‘create’ %\>  
\<% (1…3).each do |index| %\>

 \<% fields\_for :child do |f| %\> 

Childname: \<%= f.text\_field :childname, :index =\> index %\>

 \<% end %\>

\<% fields\_for :filtersetting do |r| %\>

Filtering Level: \<%= r.collection\_select(:levelid, Level.find(:all), :id, :levelname, {}, :index =\> index) %\>

\<% end %\> \<% end %\> 

\<%= submit\_tag "Submit" %\>

\<% end\_form\_tag %\> \<%= link\_to 'Back', children\_path %\>

I get the view displayed fine as i require. But insertion is not done. I  
get the error in create function.

I am unable to solve the issue.

Can anyone help me please.

Any suggestion or help from your side will be very supportive.

I have attached the screenshot of the view .

The error is unknown attribute ‘1’

KIndly help me in this regard please.

Regards,  
Swarna

---

<div class="post-metadata">

**Author:** ![rmswarna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rmswarna](https://www.ruby-forum.com/u/rmswarna)\
**Post date:** [February 25, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/multiple-rows-in-a-model/161313/2 "2009-02-25T15:15:59Z")

</div>

in which line do you get the error?

probably here:  
@child = Child.new(params[:child])

or here:  
@filter = Filtersetting.new(params[:filtersetting])

use the debugger (set it before that line) to see what’s in your  
params-hash. there is probably a key like  
:1 =\> “something”  
then you can find out, where that attribute is set and correct your  
view.
