Hello, I have a weird problem that seems way over my skill level so could use even some simple suggestions to point me in the right direction. I have a set of 6 chained dropdown menus that work fine on my computer, but do not retain the correct selections if I make the menu selections too quickly on the Heroku server. Each time a selection is made from a dropdown, the session data is updated with the following jQuery/ Ajax: # If BOOK dropdown clicked on. chapters = $(''#chapters'').html() $(''#books'').change -> book = $(''#books :selected'').text() book_id = $(''#books :selected'').val() escaped_book = book.replace(/([ #;&,.+*~\'':"!^$[\]()=>|\/@])/g, ''\\$1'') options $(chapters).filter("optgroup[label=''#{escaped_book}'']").html() options = options.replace(''selected="selected"'', "") options = (''<option value="">Select a Chapter</option>'' + options) $.ajax( url: ''/dropdowns/update_image_book'', data: "image_book_id=" + book_id) if options $(''#chapters'').html(options) $(''#chapters'').prop(''disabled'', false) $(''#sections'').html(''<option value="">Select a Section</option>'') $(''#sections'').prop(''disabled'', true) $(''#subsections'').html(''<option value="">Select a Subsection</option>'') $(''#subsections'').prop(''disabled'', true) $(''#minisections'').html(''<option value="">Select a Topic</option>'') $(''#minisections'').prop(''disabled'', true) else $(''#chapters'').empty() Here is controller: def update_image_book session[:image_book_id] = params[:image_book_id] session[:image_chapter_id] = "" session[:image_section_id] = "" session[:image_subsection_id] = "" session[:image_minisection_id] = "" redirect_to pictures_path end And the view: <%= select_tag :books, option_groups_from_collection_for_select(Subject.order(:title), :books, :title, :id, :title, get_id_from_session(:book)), :prompt => "Select a Book", :disabled => true %> After looking at the heroku logs, it looks like if I make the selections too quickly, the most recent selection runs before the line 2013-12-16T15:54:23.707522+00:00 heroku[router]: at=info method=GET path=/dropdowns/update_image_book?image_book_id=3 host=cryptic-mesa-2105.herokuapp.com fwd="75.118.31.205" dyno=web.1 connect=13ms service=32ms status=302 bytes=113 has a chance to run. Is this possible, and if so is there a better way to do this? Dave. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/212adbdf94acd401e3f6172022c4a896%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
http://en.wikipedia.org/wiki/Race_condition http://api.jquery.com/jQuery.queue/ On Dec 16, 2013, at 11:30 AM, Dave Castellano wrote:> Hello, > > I have a weird problem that seems way over my skill level so could use > even some simple suggestions to point me in the right direction. > I have a set of 6 chained dropdown menus that work fine on my computer, > but do not retain the correct selections if I make the menu selections > too quickly on the Heroku server. > > Each time a selection is made from a dropdown, the session data is > updated with the following jQuery/ Ajax: > > # If BOOK dropdown clicked on. > chapters = $(''#chapters'').html() > $(''#books'').change -> > book = $(''#books :selected'').text() > book_id = $(''#books :selected'').val() > escaped_book = book.replace(/([ #;&,.+*~\'':"!^$[\]()=>|\/@])/g, > ''\\$1'') > options > $(chapters).filter("optgroup[label=''#{escaped_book}'']").html() > options = options.replace(''selected="selected"'', "") > options = (''<option value="">Select a Chapter</option>'' + options) > $.ajax( > url: ''/dropdowns/update_image_book'', > data: "image_book_id=" + book_id) > if options > $(''#chapters'').html(options) > $(''#chapters'').prop(''disabled'', false) > $(''#sections'').html(''<option value="">Select a > Section</option>'') > $(''#sections'').prop(''disabled'', true) > $(''#subsections'').html(''<option value="">Select a > Subsection</option>'') > $(''#subsections'').prop(''disabled'', true) > $(''#minisections'').html(''<option value="">Select a > Topic</option>'') > $(''#minisections'').prop(''disabled'', true) > else > $(''#chapters'').empty() > Here is controller: > > def update_image_book > session[:image_book_id] = params[:image_book_id] > session[:image_chapter_id] = "" > session[:image_section_id] = "" > session[:image_subsection_id] = "" > session[:image_minisection_id] = "" > redirect_to pictures_path > end > > And the view: > <%= select_tag :books, > option_groups_from_collection_for_select(Subject.order(:title), :books, > :title, :id, :title, get_id_from_session(:book)), :prompt => "Select a > Book", :disabled => true %> > > After looking at the heroku logs, it looks like if I make the selections > too quickly, the most recent selection runs before the line > 2013-12-16T15:54:23.707522+00:00 heroku[router]: at=info method=GET > path=/dropdowns/update_image_book?image_book_id=3 > host=cryptic-mesa-2105.herokuapp.com fwd="75.118.31.205" dyno=web.1 > connect=13ms service=32ms status=302 bytes=113 > has a chance to run. > > Is this possible, and if so is there a better way to do this? > > Dave. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/212adbdf94acd401e3f6172022c4a896%40ruby-forum.com. > For more options, visit https://groups.google.com/groups/opt_out. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5F8EDE0B-467E-4782-9409-A7B54BA8B13C%40datatravels.com. For more options, visit https://groups.google.com/groups/opt_out.
Thanks Jason, Is this common? Dave -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1982146afcf61b9f751e6a5ab93a8ffd%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On Monday, December 16, 2013 6:38:12 PM UTC, Ruby-Forum.com User wrote:> > Thanks Jason, > > Is this common? > >Race conditions on the rails session do happen, and can''t really be fixed with the default rails session store. With this the entirety of the session is in the cookie, and your requests can look look like this request 1 sent (initial session) request 2 sent (initial session) response 1 received (sets session to intial + value set by processing of request 1) response 2 received (sets session to intial + value set by processing of request 2) so the values set by response 1 are completely obliterated. In development multiple requests are not processed in parallel so this can''t happen. I think post people don''t stick stuff in the session that is too important. I once wrote a session store (base on the active record store) ( https://github.com/fcheung/smart_session_store ) that mitigates this. It does mean that sessions are stored in the database rather than in the cookie Fred> Dave > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/94fd979d-f6a2-45e6-8e23-70488b0e9c51%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.