Module: Crm::PostsHelper

Defined in:
app/helpers/crm/posts_helper.rb

Overview

View helper for CRM posts — public www URLs, campaign-tagged referral
links, and the per-post action links rendered by the CRM post views.

See Also:

Instance Method Summary collapse

Instance Method Details

#crm_post_live_url(post, locale: 'en-US') ⇒ String

Build the public www URL for a post with the locale embedded in the path.
We construct the path directly because the named post_path helper belongs
to the CRM routes (which lack a :locale segment) and would append locale as
a query-string parameter instead.

Parameters:

  • post (Post)

    the post to link to

  • locale (String) (defaults to: 'en-US')

    locale segment for the URL path

Returns:

  • (String)

    absolute public URL



16
17
18
# File 'app/helpers/crm/posts_helper.rb', line 16

def crm_post_live_url(post, locale: 'en-US')
  "#{WEB_URL}/#{locale}/posts/#{post.slug}"
end

#crm_post_url_with_referral(post, source_or_code, locale: 'en-US') ⇒ String

Public post URL tagged for campaign attribution. Pass the Source
(preferred) to get a fully UTM-tagged link via Source#tracked_url;
a bare referral_code string still works but emits only the
referral_code param (which GA4 can't read — the link lands as Direct).

Parameters:

  • post (Post)

    the post to link to

  • source_or_code (Source, String)

    attribution source or referral code

  • locale (String) (defaults to: 'en-US')

    locale segment for the URL path

Returns:

  • (String)

    absolute URL with attribution params



29
30
31
32
33
34
# File 'app/helpers/crm/posts_helper.rb', line 29

def crm_post_url_with_referral(post, source_or_code, locale: 'en-US')
  base = crm_post_live_url(post, locale: locale)
  return source_or_code.tracked_url(base) if source_or_code.is_a?(Source)

  "#{base}?referral_code=#{ERB::Util.url_encode(source_or_code)}"
end

#localized_body(post) ⇒ String?

Localized solution body for the post, if present.

Parameters:

  • post (Post)

    the post whose solution to localize

Returns:

  • (String, nil)

    localized content, or nil when no solution



82
83
84
85
86
# File 'app/helpers/crm/posts_helper.rb', line 82

def localized_body(post)
  return unless (b = post.solution.presence)

  localize_content(b)
end

#post_commands(post) ⇒ Array<String>

Build the action links for a single post.

Parameters:

  • post (Post)

    the post to render commands for

Returns:

  • (Array<String>)

    safe HTML link fragments



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/crm/posts_helper.rb', line 40

def post_commands(post)
  cmds = []
  cmds << link_to('Edit Post', edit_post_path(post), data: { turbo_action: 'replace' }) if can?(:update, post)
  cmds << link_to('Clone Post', clone_post_path(post), data: { turbo_method: :post }) if can?(:create, Post)
  cmds.concat(article_revision_command_options(post))

  cmds << link_to('Check Internal Links', check_links_post_path(post), data: { turbo_method: :post }) if can?(:update, post)
  cmds << link_to('Link Analysis', link_checks_path(q: { articles_id_eq: post.id }))
  cmds << link_to('Image Analysis', blog_image_checks_path)
  cmds << link_to('See Post Comments', post_post_comments_path(post_id: post.id))
  cmds << link_to('Flush Cache', flush_cache_post_path(post), data: { turbo_method: :post }) if can?(:update, post)

  # Add confirmation if schema markup already exists
  extract_schema_options = { data: { turbo_method: :post } }
  extract_schema_options[:data][:turbo_confirm] = 'This post already has schema markup. Are you sure you want to extract and potentially overwrite it?' if post.schema_markup.present?
  cmds << link_to('Extract Schema', extract_schema_post_path(post), extract_schema_options) if can?(:update, post)

  cmds << link_to('Delete', post_path(post), data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to destroy the post: #{post.title}" }) if can?(:destroy, post)
  cmds
end

#post_title(post) ⇒ String

Linked, truncated post title for index listings.

Parameters:

  • post (Post)

    the post to title-link

Returns:

  • (String)

    safe HTML link



74
75
76
# File 'app/helpers/crm/posts_helper.rb', line 74

def post_title(post)
  link_to post.title[0..65], post_path(post)
end

#revision_state_badge(revision, is_current: nil) ⇒ String

Returns a Bootstrap badge for the revision status (current or past).

Parameters:

  • revision (ArticleRevision)

    the revision to badge

  • is_current (Boolean, nil) (defaults to: nil)

    whether the revision is the live one

Returns:

  • (String)

    safe HTML badge



66
67
68
# File 'app/helpers/crm/posts_helper.rb', line 66

def revision_state_badge(revision, is_current: nil)
  article_revision_state_badge(revision, current: is_current)
end