module JsApplicationReloader::ControllerExtensions

Public Class Methods

included(base) click to toggle source
# File lib/js_application_reloader/controller_extensions.rb, line 4
def self.included(base)
  base.before_filter :handle_js_application_reloader_token_expiration
end

Public Instance Methods

handle_js_application_reloader_token_expiration() click to toggle source
# File lib/js_application_reloader/controller_extensions.rb, line 8
def handle_js_application_reloader_token_expiration
  # Note: we do a string comparision to avoid 232323 not matching "232323" mistakes
  if request.headers[JsApplicationReloader.token_header_name] && (request.headers[JsApplicationReloader.token_header_name].to_s != JsApplicationReloader.token.to_s)
    response.headers[JsApplicationReloader.status_header_name] = 'token_expired'
    render_js_application_reloader_expiration
  end
end
render_js_application_reloader_expiration() click to toggle source

override me in your ApplicationController to customize what gets sent back to the client on token expiration

# File lib/js_application_reloader/controller_extensions.rb, line 18
def render_js_application_reloader_expiration
  message = "A new version of #{JsApplicationReloader.application_name} is available. " +
        "Please click <a href='#{JsApplicationReloader.redirect_url}'>here</a> to load it."

  respond_to do |format|
    format.html {
      render :text => message, :status => JsApplicationReloader.reload_required_http_status
    }
    format.json {
      render :json => {:message => message}, :status => JsApplicationReloader.reload_required_http_status
    }
  end
end