Module: RenderAsync::ViewHelper

Defined in:
lib/render_async/view_helper.rb

Instance Method Summary collapse

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/render_async/view_helper.rb', line 20

def render_async(path, options = {}, &placeholder)
  html_element_name = options.delete(:html_element_name) || 'div'
  container_id = options.delete(:container_id) || generate_container_id
  container_class = options.delete(:container_class)
  event_name = options.delete(:event_name)
  placeholder = capture(&placeholder) if block_given?
  method = options.delete(:method) || 'GET'
  data = options.delete(:data)
  headers = options.delete(:headers) || {}
  error_message = options.delete(:error_message)
  error_event_name = options.delete(:error_event_name)

  render 'render_async/render_async', html_element_name: html_element_name,
                                      container_id: container_id,
                                      container_class: container_class,
                                      path: path,
                                      html_options: options,
                                      event_name: event_name,
                                      placeholder: placeholder,
                                      method: method,
                                      data: data,
                                      headers: headers,
                                      error_message: error_message,
                                      error_event_name: error_event_name
end

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



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

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



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

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