Module: DiscoApp::ApplicationHelper

Defined in:
app/helpers/disco_app/application_helper.rb

Instance Method Summary collapse

Instance Method Details

Generate a link that will open its href in an embedded Shopify modal.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/disco_app/application_helper.rb', line 15

def link_to_modal(name, path, options = {})
  modal_options = {
    src: path,
    title: options.delete(:modal_title),
    width: options.delete(:modal_width),
    height: options.delete(:modal_height),
    buttons: options.delete(:modal_buttons),
  }
  options[:onclick] = "ShopifyApp.Modal.open(#{modal_options.to_json}); return false;"
  options[:onclick].gsub!(/"function(.*?)"/, 'function\1')
  link_to(name, path, options)
end

Generates a link pointing to an object (such as an order or customer) inside the given shop’s Shopify admin. This helper makes it easy to create links to objects within the admin that support both right-clicking and opening in a new tab as well as capturing a left click and redirecting to the relevant object using ‘ShopifyApp.redirect()`.



8
9
10
11
12
# File 'app/helpers/disco_app/application_helper.rb', line 8

def link_to_shopify_admin(shop, name, admin_path, options = {})
  options[:onclick] = "ShopifyApp.redirect('#{admin_path}'); return false;"
  options[:'data-no-turbolink'] = true
  link_to(name, "https://#{shop.shopify_domain}/admin/#{admin_path}", options)
end