diff --git a/app/models/dapp.rb b/app/models/dapp.rb index 21e1a16..1b6dfba 100644 --- a/app/models/dapp.rb +++ b/app/models/dapp.rb @@ -17,4 +17,16 @@ class Dapp < ApplicationRecord exchange: 30, } + def name_or_default + name.blank? ? name_zh_cn : name + end + + def intro_or_default + intro.blank? ? intro_zh_cn : intro + end + + def desc_or_default + desc.blank? ? desc_zh_cn : desc + end + end diff --git a/app/models/dapp_type.rb b/app/models/dapp_type.rb index 13e349f..6d48c91 100644 --- a/app/models/dapp_type.rb +++ b/app/models/dapp_type.rb @@ -6,4 +6,8 @@ class DappType < ApplicationRecord globalize_accessors scope :default_order, -> { order(id: :asc) } + + def name_or_default + name.blank? ? name_zh_cn : name + end end diff --git a/app/views/dapps/show.html.erb b/app/views/dapps/show.html.erb index 65292b5..c20e2d3 100644 --- a/app/views/dapps/show.html.erb +++ b/app/views/dapps/show.html.erb @@ -1,14 +1,14 @@ -<% @page_title = @dapp.name || @dapp.name_zh_cn %> +<% @page_title = @dapp.name_or_default %>
- data-name=<%= @dapp.name || @dapp.name_zh_cn %> + data-category=<%= @dapp.dapp_type.name_or_default %> + data-name=<%= @dapp.name_or_default %> >
alt="mainimg"> -
<%= @dapp.name || @dapp.name_zh_cn %>
+
<%= @dapp.name_or_default %>
><%= @dapp.url_address %>
<% @star.times do |i| %> @@ -24,7 +24,7 @@
<%= t("overview") %>
- <%= @dapp.intro || @dapp.intro_zh_cn %> + <%= @dapp.intro_or_default %>
<%= t("submitted_at") %>: <%= @dapp.publish_at&.strftime("%Y-%m-%d") %>