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.
Instance Method Summary collapse
-
#crm_post_live_url(post, locale: 'en-US') ⇒ String
Build the public www URL for a post with the locale embedded in the path.
-
#crm_post_url_with_referral(post, source_or_code, locale: 'en-US') ⇒ String
Public post URL tagged for campaign attribution.
-
#localized_body(post) ⇒ String?
Localized
solutionbody for the post, if present. -
#post_commands(post) ⇒ Array<String>
Build the action links for a single post.
-
#post_title(post) ⇒ String
Linked, truncated post title for index listings.
-
#revision_state_badge(revision, is_current: nil) ⇒ String
Returns a Bootstrap badge for the revision status (current or past).
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.
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).
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.
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.
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((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 = { data: { turbo_method: :post } } [: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), ) 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.
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).
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 |