# Some sort of array

**URL:** <https://www.ruby-forum.com/t/some-sort-of-array/73766>\
**Category:** Ruby\
**Created:** [October 26, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/some-sort-of-array/73766 "2006-10-26T22:34:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 26, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/some-sort-of-array/73766/1 "2006-10-26T22:34:48Z")

</div>

Well this is happening in a Rails app but thought I’d try here to find  
some  
help or guidance.  
Basically within my web form, multiple text fields take input for the  
same  
method. I’m creating seperate records from each value submitted.

\<%= text\_field(:cantitle, :title\_opt, “index” =\> 1)%\>  
\<%= text\_field(:cantitle, :title\_opt, “index” =\> 2)%\>  
\<%= text\_field(:cantitle, :title\_opt, “index” =\> 3)%\>

The above get converted to this where each field has a unique id.

To get them into the database  
a = params[‘cantitle’]  
a.each {|k, v|  
cantitle = Cantitle.new  
…  
…  
cantitle.title\_opt = v[:title\_opt]  
cantitle.save }

Which works fine except I can’t figure out how to test if there are no  
values input. It looks like an empty array is created regardless. As  
below:  
{“cantitle”=\>{“1”=\>{“title\_opt”=\>""}, “2”=\>{“title\_opt”=\>""},  
“3”=\>{“title\_opt”=\>""}}, # with no values input in form

{“cantitle”=\>{“1”=\>{“title\_opt”=\>"something "},  
“2”=\>{“title\_opt”=\>“else”},  
“3”=\>{“title\_opt”=\>“nope”}} # with values input

It seems like I’d have to test EACH value .  
I tried unless v[:title\_opt].empty? cantitle.title\_opt = v[:title\_opt]  
Though that didn’t seem to have any effect.

Appreciate any suggestions on this one.  
TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 26, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/some-sort-of-array/73766/2 "2006-10-26T23:00:51Z")

</div>

Never mind , I solved it right after writing. (Sometimes writing helps  
my  
problem solving :).

a = params[‘cantitle’]  
a.each {|k, v|  
cantitle = Cantitle.new  
cantitle.candidate\_id = @candidate\_id  
cantitle.user\_id = current\_user.id  
unless v[:title\_opt].blank?  
cantitle.title\_opt = v[:title\_opt]  
cantitle.save  
end  
}

Sorry  
Stuart
