Module: RenderAsync::ViewHelper

Defined in:
lib/render_async/view_helper.rb

Instance Method Summary collapse

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/render_async/view_helper.rb', line 19

def render_async(path, options = {}, &placeholder)
  event_name = options.delete(:event_name)
  placeholder = capture(&placeholder) if block_given?

  render 'render_async/render_async', **container_element_options(options),
                                      path: path,
                                      html_options: html_options(options),
                                      event_name: event_name,
                                      placeholder: placeholder,
                                      **request_options(options),
                                      **error_handling_options(options),
                                      **retry_options(options),
                                      **polling_options(options),
                                      **content_for_options(options)
end

#render_async_cache(path, options = {}, &placeholder) ⇒ Object



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

def render_async_cache(path, options = {}, &placeholder)
  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, options, &placeholder)
  end
end

#render_async_cache_key(path) ⇒ Object



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

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