Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

The strange and wonderful world of forgotten Rails features: HTTP Streaming

View Railscasts 1 projects_controller.rb
1 2 3 4 5 6 7
class ProjectsController < ApplicationController
stream
 
def index
# rest of controller code
end
end
View Railscasts 1 projects_controller.rb
1 2 3 4 5 6 7 8
class ProjectsController < ApplicationController
respond_to :html
 
def index
@projects = Project.scoped
respond_with @projects, stream: true
end
end
View Railscasts 1 projects_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
worker_processes 3
timeout 30
preload_app true
port = ENV["PORT"].to_i
listen port, tcp_nopush: false
 
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
sleep 1
end
 
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
if defined?(ActiveSupport::Cache::DalliStore) && Rails.cache.is_a?(ActiveSupport::Cache::DalliStore)
# Reset Rails's object cache
# Only works with DalliStore
Rails.cache.reset
 
# Reset Rails's session store
# If you know a cleaner way to find the session store instance, please let me know
ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.