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