Module: GetSchwifty::Helper

Defined in:
lib/get_schwifty/helper.rb

Overview

:nodoc

Instance Method Summary collapse

Instance Method Details

#get_schwifty(route, params = nil, &blk) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/get_schwifty/helper.rb', line 4

def get_schwifty(route, params = nil, &blk)
  id = SecureRandom.hex
  Rails.cache.write("get_schwifty:#{id}", route)

  opts = {
    "data-get-schwifty" => id
  }

  opts["data-get-schwifty-params"] = params.to_json if params

  args = [
    :div, nil, opts
  ]

  if block_given?
    args.reject!(&:nil?)
    return (*args, &blk)
  end

  (*args)
end