Module: ActiveVersioning::Workflow::PreviewLink

Included in:
ActionsWithPreview, ShowResource
Defined in:
lib/active_versioning/workflow/preview_link.rb

Instance Method Summary collapse

Instance Method Details



4
5
6
7
8
9
# File 'lib/active_versioning/workflow/preview_link.rb', line 4

def preview_link_for(resource, link_options={})
  link_to I18n.t('active_versioning.links.preview'), preview_path_for(resource), link_options.merge(
    class:  'preview-link',
    target: :blank
  )
end

#preview_path_for(resource, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/active_versioning/workflow/preview_link.rb', line 11

def preview_path_for(resource, options = {})
  resource_path = proc do |resource|
    param     = resource.try(:slug) || resource.to_param
    route_key = resource.model_name.singular_route_key

    options.fetch(:context, self).send("#{route_key}_path", param, _preview: true)
  end

  resource.try(:path, _preview: true) || resource_path.call(resource)
end