I have 3 text fields in a form , all with the same method, since those
params will
be inserted via a loop which is set up in the create action.
However, I’m noticing that the form is only sending through the 1st
value
and leaving out the additional 2.
In my form I have this:
<%= text_field(:cantitle, :title_opt)%>
<%= text_field(:cantitle, :title_opt)%>
<%= text_field(:cantitle, :title_opt)%>
Even though I put input into each , the params came through as such:
{“cantitle”=>{“title_opt”=>“CEO”}, # so the 2nd and 3rd were skipped.
In the controller I have this loop- # which if 3 values were submitted ,
3
records would be created.
a = (params[:cantitle][:title_opt])
a.each {|x|
cantitle = Cantitle.new
cantitle.title_opt = x
cantitle.save }
Any ideas how to get each value through ? Also, I’m wondering what would
happen if someone filled in the 1st and 3rd box and left the 2nd blank.
Do
I have to account for a null value ?
Bala, thanks - you always come through for me.
Actually though it is possible (as I just learned) by adding “index” = x
So now I have the text fields as such:
<%= text_field(:cantitle, :title_opt, “index” => 1)%>
<%= text_field(:cantitle, :title_opt, “index” => 2)%>
<%= text_field(:cantitle, :title_opt, “index” => 3)%>
Which get translated into :
And params are such:
“cantitle”=>{“1”=>{“title_opt”=>“CEO”}, “2”=>{“title_opt”=>“COO”},
“3”=>{“title_opt”=>“CIO”}},