From: Dark Ambient Date: 2006-10-27T05:59:31+09:00 Subject: Re: Some sort of array ------=_Part_19021_19483263.1161896367974 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 On 10/26/06, Dark Ambient wrote: > > 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. > > type="text" /> > type="text" /> > type="text" /> > > 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 > -- > http://en.wikipedia.org/wiki/Dark_ambient > > -- http://en.wikipedia.org/wiki/Dark_ambient ------=_Part_19021_19483263.1161896367974--