diff --git a/app/models/asset.rb b/app/models/asset.rb index 617f04967..b591ab9cf 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -9,7 +9,10 @@ class Asset field :description, localize: true field :title, localize: true - validates_presence_of :title, :data, :description + validates :title, :at_least_one => true + validates :description, :at_least_one => true + validates_presence_of :data + belongs_to :asset_category belongs_to :assetable, polymorphic: true diff --git a/config/initializers/custom_validators.rb b/config/initializers/custom_validators.rb new file mode 100644 index 000000000..1b3a9f2cb --- /dev/null +++ b/config/initializers/custom_validators.rb @@ -0,0 +1,7 @@ +class AtLeastOneValidator < ActiveModel::EachValidator + + def validate_each(record, attribute, value) + record.errors[attribute] << (options[:message] || I18n.t("errors.at_least_one")) if (value.blank? || value.values.join.eql?('')) + end + +end \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 98a0d1a89..93fbcc108 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -79,6 +79,9 @@ en: visitors_this_month: This month's visitors visitors_this_year: This year's visitors + errors: + at_least_one: must at least have one value + admin: access: denied: diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3fbb2574b..79251f922 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -77,6 +77,9 @@ zh_tw: visitors_this_month: 本月造訪 visitors_this_year: 今年造訪 + errors: + at_least_one: 必須至少有一個值 + admin: access: denied: diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index e6986466a..63cdde945 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -58,7 +58,7 @@ class Bulletin accepts_nested_attributes_for :bulletin_files, :allow_destroy => true accepts_nested_attributes_for :bulletin_links, :allow_destroy => true - validates :title, :presence => true + validates :title, :at_least_one => true before_save :check_deadline,:update_status,:update_avliable_language diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb index 989c0564c..8c8f22958 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb @@ -17,11 +17,11 @@
  • <%= t('announcement.subtitle') %> - <%= @bulletin.subtitle.html_safe %> + <%= @bulletin.subtitle.html_safe rescue '' %>
  • <%= t('announcement.text') %> - <%= @bulletin.text.html_safe %> + <%= @bulletin.text.html_safe rescue '' %>
  • diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb index 11401f13f..af1ca12c3 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb @@ -12,7 +12,7 @@ <%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
    - <%= @bulletin.text.html_safe %> + <%= @bulletin.text.html_safe rescue '' %>
    <% if @bulletin.bulletin_links.size > 0 %> diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index e33c638b1..6c87e0181 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -59,7 +59,7 @@ class NewsBulletin accepts_nested_attributes_for :news_bulletin_files, :allow_destroy => true accepts_nested_attributes_for :news_bulletin_links, :allow_destroy => true - validates_presence_of :title + validates :title, :at_least_one => true before_save :update_status,:update_avliable_language diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/show.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/show.html.erb index 5d2b4dcbf..686a1ee1b 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/show.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/show.html.erb @@ -17,11 +17,11 @@
  • <%= t('news.subtitle') %> - <%= @news_bulletin.subtitle.html_safe %> + <%= @news_bulletin.subtitle.html_safe rescue '' %>
  • <%= t('news.text') %> - <%= @news_bulletin.text.html_safe %> + <%= @news_bulletin.text.html_safe rescue '' %>
  • diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb index f5bc945aa..b7b1f57af 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb @@ -24,7 +24,7 @@ <%= image_tag post.image rescue nil %> <%= link_to post.title, panel_news_front_end_news_bulletin_path(post), :class => 'news_title' %> - <%= post.subtitle.html_safe %> + <%= post.subtitle.html_safe rescue '' %> <%= display_date(post.postdate) %> diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb index 268825f4d..edd8a9e1a 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb @@ -14,7 +14,7 @@ <%= link_to image_tag(@news_bulletin.image.url, :size => "320x240"), @news_bulletin.image.url, {:target => '_blank', :title => @news_bulletin.image_identifier} if @news_bulletin.image.file %>
    - <%= @news_bulletin.text.html_safe %> + <%= @news_bulletin.text.html_safe rescue '' %>
    <% if @news_bulletin.news_bulletin_links.size > 0 %> diff --git a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/_index.html.erb b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/_index.html.erb index 205c28285..39af5c14b 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/_index.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/_index.html.erb @@ -16,7 +16,7 @@ <%= image_tag post.image %> <%= link_to post.title, panel_news_front_end_news_bulletin_path(post), :class => 'news_title' %> - <%= post.subtitle.html_safe %> + <%= post.subtitle.html_safe rescue '' %> <%= display_date(post.postdate) %> diff --git a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/home_banner.html.erb b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/home_banner.html.erb index db6fe07ea..eb3cf591d 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/home_banner.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/home_banner.html.erb @@ -21,7 +21,7 @@
  • <%= image_tag(post.image.url, :size => "290x130") if post.image.file %>

    <%= link_to post.title, panel_news_front_end_news_bulletin_path(post, :category_id => post.news_bulletin_category_id) %>

    -

    <%= post.subtitle.html_safe %>

    +

    <%= post.subtitle.html_safe rescue '' %>

  • <% end %> diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/show.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/show.html.erb index 913be9835..242dde679 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/show.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/show.html.erb @@ -13,7 +13,7 @@
  • <%= t('page_content.context') %> - <%= @page_context.context.html_safe %> + <%= @page_context.context.html_safe rescue '' %>
  • <%= t('page_content.張貼者') %> diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb index 6648b46b6..3e607ad4c 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb @@ -4,8 +4,8 @@

    <%= flash_messages %>

    <%= dislpay_view_count(@page_context) %>
    -

    <%= @page_context.page.title rescue nil %>

    +

    <%= @page_context.page.title rescue '' %>

    -
    <%= @page_context.context.html_safe rescue nil %>
    +
    <%= @page_context.context.html_safe rescue '' %>
    diff --git a/vendor/built_in_modules/web_resource/app/models/web_link.rb b/vendor/built_in_modules/web_resource/app/models/web_link.rb index be1f9682d..8e0216f23 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link.rb @@ -21,7 +21,7 @@ class WebLink belongs_to :web_link_category - validates_presence_of :title + validates :title, :at_least_one => true def self.search( category_id = nil )