Hi there once again, I''ve got stumped on something simple once again, I have the following in a view: <%= link_to_function ''Add another answer'', "new Insertion.Bottom(''answerslist'', $(''answer_form'').innerHTML)" %> <ol id=''answerslist''></ol> <span id=''answer_form'' style=''display:none;''> <li><%= text_field_tag "answers[]" %></li> </span> Which allows me to append new elements to answers[]. But the problem is that an empty string is always present at the end of the array. When its supposed to be empty (nothing added) there is precisely one empty string, and when there''s more than one answer in the array, the last one is still an empty string. At present I''m fixing this in the controller with the following: @answers = params[:answers] @answers.each{ |a| @question.answers << Answer.new( :description => a ) unless a == "" } But it''s not exactly fixing the actual problem. I''m not actually even sure if this is a bug on my behalf, or if its just the way its supposed to behave. Can anyone put me right? Cheers, -v -- keys: http://codex.net/gpg.asc Scientist: A left-over from the age of reason (pre 1982)
Mark Reginald James
2005-Dec-13 11:11 UTC
Re: Help with AJAX, controller receiving extra data
Vincent AE Scott wrote:> <%= link_to_function ''Add another answer'', "new > Insertion.Bottom(''answerslist'', $(''answer_form'').innerHTML)" %> > > <ol id=''answerslist''></ol> > > <span id=''answer_form'' style=''display:none;''> > <li><%= text_field_tag "answers[]" %></li> > </span> > > Which allows me to append new elements to answers[]. > But the problem is that an empty string is always present at the end of > the array. When its supposed to be empty (nothing added) there is > precisely one empty string, and when there''s more than one answer in the > array, the last one is still an empty string.Is your ''answer_form'' span inside your form or outside? Make sure it''s outside. -- We develop, watch us RoR, in numbers too big to ignore.
Vincent AE Scott
2005-Dec-13 11:33 UTC
Re: Re: Help with AJAX, controller receiving extra data
#if mrj /* Dec 13, 10:11 */> Vincent AE Scott wrote: > > ><%= link_to_function ''Add another answer'', "new > >Insertion.Bottom(''answerslist'', $(''answer_form'').innerHTML)" %> > > > ><ol id=''answerslist''></ol> > > > ><span id=''answer_form'' style=''display:none;''> > > <li><%= text_field_tag "answers[]" %></li> > ></span> > > > >Which allows me to append new elements to answers[]. > >But the problem is that an empty string is always present at the end of > >the array. When its supposed to be empty (nothing added) there is > >precisely one empty string, and when there''s more than one answer in the > >array, the last one is still an empty string. > > Is your ''answer_form'' span inside your form or outside? Make sure > it''s outside. >#endif /* mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org */ Ahhhh, Bingo! Cheers for that, makes perfect sense now. Gotta love this list :) -- keys: http://codex.net/gpg.asc Recession: Economic downturn entirely due to external factors Recovery: Economic upturn entirely due to government action