Help with AJAX, controller receiving extra data


#1

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)” %>

  1. <%= text_field_tag "answers[]" %>
  2. 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)


    #2

    Vincent AE Scott wrote:

    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.


    #3

    #if mrj /* Dec 13, 10:11 */

    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 /* removed_email_address@domain.invalid */

    Ahhhh, Bingo! Cheers for that, makes perfect sense now. Gotta love
    this list :slight_smile:


    keys: http://codex.net/gpg.asc

    Recession: Economic downturn entirely due to external factors
    Recovery: Economic upturn entirely due to government action