[Rails] Storing Rails controller callback data in session
The idea is:
- Perform some time consuming action in background.
- Have the results from that action be propagated back to the controller using a callback.
- Store the result in an in memory session store.
- Have the result in session be used and available from that point onward.
Controller receives the results in the callback, as expected.
# controller callback, saves result to session # this method is executed as expected # session id matches the one from other controller actions def on_counter_value_calculated(context, new_value) @counter = new_value session[:counter] = @counter end
However, stored session is lost in subsequent calls.
# although the same session is targeted (same id) # the saved value is not the same def index @counter = session[:counter] || 0 end
I've created a small Rails project that demonstrates the issue:https://github.com/elvanja/controller_callbak_store_in_session
Any input appreciated.
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2b876660-521d-4217-9840-8fbbe2ac6364%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home