Ruby on Rails Sunday, May 1, 2011

Frederick Cheung wrote in post #996132:
> Have you checked the browser's JavaScript console for any errors? That
> last line looks suspicious to me. I would have thought $
> (value.form).submit() would suffice.
> Also I think this general approach might be built on slightly shaky
> approach - Since the whole form is being submitted each time, the last
> request (for example) is probably going to be sending all the
> information from the previous iterations (and of course there's no
> guarantee they'll get processed in exactly the same order they were
> sent in - a true vote on the 5th item could get overwritten when the
> form is submitted for the 4th time). Personally I'd build up a single
> hash of all the data I wanted to submit and use $.post to send it.
>
> Fred

Thanks, changing the last line to $(value.form).submit() worked! I
notice a slight problem, however, which is that sometimes the newly
updated approval field is not immediately shown after the controller
serves up the ballots_path. Sometimes I need to refresh in order for me
to see the newly-updated fields. Is this a problem with RoR (a delay?)
or my sloppy implementation?

Also, I understand that submitting the entire form is a poor solution to
the problem but this is literally the first time I've ever submitted a
remote form with JavaScript before so it was first thing I came up with.
Would my code easily translate to this $.post() solution? I imagine that
if I used .post() I wouldn't have to rely on hidden form data which
would be nice.

Thanks again!

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment