# Single Text\_Area for multiple records

**URL:** <https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990>\
**Category:** Rails\
**Created:** [November 24, 2008, 12:26pm UTC](https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990 "2008-11-24T12:26:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smfrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@smfrick](https://www.ruby-forum.com/u/smfrick)\
**Post date:** [November 24, 2008, 12:26pm UTC](https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990/1 "2008-11-24T12:26:22Z")

</div>

I have an application I’ve developed where there is a record of data  
which is entered line by line, I’ve got that working fine. The form  
now only has one field, because that’s all the data which is  
required. I would like to make it simpler by providing a text\_area,  
and the user would enter a list of values and on submit have the  
controller or the model parse the data into records and append them  
into the table. I’ve looked for examples of the correct ‘Rails way’  
of doing this type of process, but everything looks like a single  
record posted. Does anyone know of a Gem or module which will make  
this simpler?

Thanks!

---

<div class="post-metadata">

**Author:** ![smfrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@smfrick](https://www.ruby-forum.com/u/smfrick)\
**Post date:** [November 24, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990/2 "2008-11-24T15:43:34Z")

</div>

Perhaps, and this is just some “brain dump” at the moment, you could  
set up a separate attribute and then use some Ruby to take that imput  
and split it so that you can save it as separate attributes. I have no  
idea how you would do this code wise, but having a text field set up  
as :input and then attr\_accesssor :input and then work from there with  
some Ruby to split at newlines or with some other kind of operator.

---

<div class="post-metadata">

**Author:** ![smfrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@smfrick](https://www.ruby-forum.com/u/smfrick)\
**Post date:** [November 24, 2008, 4:35pm UTC](https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990/3 "2008-11-24T16:35:04Z")

</div>

That’s a great Idea, It’s the How I’m trying to figure out. This is  
a simple task in PHP or ASP, but Ruby is a different animal  
completely, and I don’t want to buck the system. Thanks for your  
input.

---

<div class="post-metadata">

**Author:** ![smfrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@smfrick](https://www.ruby-forum.com/u/smfrick)\
**Post date:** [December 7, 2008, 10:48am UTC](https://www.ruby-forum.com/t/single-text-area-for-multiple-records/153990/4 "2008-12-07T10:48:14Z")

</div>

Hey smfrick,

I just encountered this same problem, here’s a rather hacked together  
solution, maybe some people here can help optimize it:

def create  
#GRAB FORM DATA  
@temp\_array = params[:form\_name]  
#GET ARRAY MADE OF EACH LINE OF TEXT\_AREA  
@temp\_array = @temp\_array[“text\_area”].split(/[\r\n]/)  
#VARIABLE TO ENSURE AT LEAST ONE RECORD WAS SAVED  
@success = 0  
#LOOP  
@temp\_array.each do |temp\_individual\_record|  
if temp\_individual\_record.length()\>0 #ENSURE NO BLANKS  
@model = ModelName.new(params[:form\_name]) #GRAB ANY OTHER  
FIELDS  
@model.text\_area=temp\_individual\_record #OVERWRITE TEXTAREA  
@model.save  
@success=1  
end  
end  
respond\_to do |format|  
if @success==1  
flash[:notice] = ‘Model was successfully created.’  
format.html { redirect\_to(@model) }  
format.xml { render :xml =\> @model, :status  
=\> :created, :location =\> @model }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @model.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end
