From 115a0b26cf3a09ea0fcae18b12bb7d1bd437edc1 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Tue, 9 Jun 2026 16:50:13 +0800 Subject: [PATCH] add mask_ask_name helper, show created_at, published_index date and masked name --- app/helpers/admin/asks_helper.rb | 23 +++++++++++++++++++++++ app/views/asks/published_index.erb | 5 +++-- app/views/asks/show.html.erb | 8 +++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin/asks_helper.rb b/app/helpers/admin/asks_helper.rb index 4278c26..b4be74e 100644 --- a/app/helpers/admin/asks_helper.rb +++ b/app/helpers/admin/asks_helper.rb @@ -10,6 +10,29 @@ module Admin::AsksHelper extend ActionView::Helpers::UrlHelper extend OrbitFormHelper extend Ckeditor::Helpers::FormHelper + def mask_ask_name(name) + return name if name.blank? + first_char = name[0] + if first_char =~ /\p{Han}/ + cleaned = name.gsub(/[^\p{Han}\s]/, '') + char_count = cleaned.scan(/\p{Han}/).length + if char_count <= 1 + cleaned + elsif char_count <= 3 + cleaned[0] + '〇〇' + else + cleaned[0..1] + '〇〇' + end + else + cleaned = name.gsub(/\p{Han}/, '') + words = cleaned.split(' ').reject(&:blank?) + if words.length <= 1 + words[0].to_s + else + words[1] + '..' + end + end + end def get_categories_info_for_ask current_user = OrbitHelper.current_user OrbitHelper.set_params(params,current_user) diff --git a/app/views/asks/published_index.erb b/app/views/asks/published_index.erb index 0f39666..1994991 100644 --- a/app/views/asks/published_index.erb +++ b/app/views/asks/published_index.erb @@ -12,10 +12,11 @@ %>
+
<%= ask_question.created_at.strftime('%Y-%m-%d') %>
<%= link_to ask_question.title,"#{data['url']}?item=#{ask_question.id}",title: ask_question.title %>
<%= ask_question.content %>
-
<%= ask_question.name %>
+
<%= mask_ask_name(ask_question.name) %>
<%= ask_question[:identity] %>
@@ -67,4 +68,4 @@
<% total_pages = data['ask_questions'].total_pages %> -<%= create_pagination(total_pages).html_safe if total_pages > 1 %> \ No newline at end of file +<%= create_pagination(total_pages).html_safe if total_pages > 1 %> diff --git a/app/views/asks/show.html.erb b/app/views/asks/show.html.erb index 04e6826..cd58aac 100644 --- a/app/views/asks/show.html.erb +++ b/app/views/asks/show.html.erb @@ -55,6 +55,12 @@
+
+ <%= label_tag nil,t('mongoid.attributes.ask_question.created_at'), :class=> 'control-label' %> +
+ <%= label_tag nil,ask.created_at.strftime('%Y-%m-%d'), :class=> 'control-label' %> +
+
<%= label_tag nil,t('category'), :class=> 'control-label' %>
@@ -71,7 +77,7 @@
<%= label_tag nil,t('mongoid.attributes.ask_question.name'), :class=> 'control-label' %>
- <%= label_tag nil,ask.name, :class=> 'control-label' %> + <%= label_tag nil,mask_ask_name(ask.name), :class=> 'control-label' %>
<% end %>