Module: RenderAsync::ViewHelper

Defined in:
lib/render_async/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_async(path, html_options = {}, &placeholder) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/render_async/view_helper.rb', line 19

def render_async(path, html_options = {}, &placeholder)
  container_id = "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
  placeholder = capture(&placeholder) if block_given?

  render 'render_async/render_async', container_id: container_id,
                                      path: path,
                                      html_options: html_options,
                                      placeholder: placeholder
end

#render_async_cache(path, html_options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/render_async/view_helper.rb', line 10

def render_async_cache(path, html_options = {})
  cached_view = Rails.cache.read("views/#{render_async_cache_key(path)}")
  if cached_view.present?
    render :html => cached_view.html_safe
  else
    render_async(path, html_options)
  end
end

#render_async_cache_key(path) ⇒ Object



6
7
8
# File 'lib/render_async/view_helper.rb', line 6

def render_async_cache_key(path)
  "render_async_#{path}"
end