Some sort of array

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.

<input id="cantitle_1_title_opt" name="cantitle[1][title_opt]" size="30"
type="text" />
<input id="cantitle_2_title_opt" name="cantitle[2][title_opt]" size="30"
type="text" />
<input id="cantitle_3_title_opt" name="cantitle[3][title_opt]" size="30"
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

···

--

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 <sambient@gmail.com> 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.

<input id="cantitle_1_title_opt" name="cantitle[1][title_opt]" size="30"
type="text" />
<input id="cantitle_2_title_opt" name="cantitle[2][title_opt]" size="30"
type="text" />
<input id="cantitle_3_title_opt" name="cantitle[3][title_opt]" size="30"
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
--
Dark ambient - Wikipedia

--