4 ms·
Non-Message Flash in Rails
- patio11 12y agoI've previously used it to "queue up" asynchronous poll-style AJAX in controllers. e.g. flash[:pollers] ||= [] flash[:pollers].push({:url => {:action => "foo", :controller => "bar", :id => 42}, :interval => 1000, :callbacks => "whatever"}) This gets consumed by a helper method in the head of the my templates, which, if any pollers are present, does jQuery.ready() and then fires them. As to why I'd rather the controller taking care of this than the view, that's largely a personal preference thing. A frequent pattern: @lots_of_models = Model.find(...) @lots_of_models.each do |model| unless model.some_expensive_calculation_is_cached? model.send_later :some_expensive_calculation #queue workers do this out of process add_poller("model-#{model.id}", :action => "expensive_calculation_results") #convenience method with intelligent defaults end