From d386174c9726f8763889ce28b826f4783a7b1455 Mon Sep 17 00:00:00 2001 From: Ruling-iMac Date: Thu, 30 Apr 2015 18:31:40 +0800 Subject: [PATCH] add function : redirect to homepage --- app/controllers/pages_controller.rb | 6 +++++- app/models/site.rb | 1 + app/views/admin/sites/preference.html.erb | 8 ++++++++ config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 864e8b1..3b3f4bb 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -119,7 +119,11 @@ class PagesController < ApplicationController end render :html => render_final_page("#{module_app}/#{params[:target_action]}",page,layout).html_safe else - render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found + if Site.first.enable_redirect_index + redirect_to root_url + else + render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found + end end else render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found diff --git a/app/models/site.rb b/app/models/site.rb index ed4f3c7..f58d7ba 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -23,6 +23,7 @@ class Site field :mobile_api_openness_on, :type => Boolean, :default => false field :desktop_closed, :type => Boolean, :default => false field :enable_language_detection, :type => Boolean, :default => false + field :enable_redirect_index, :type => Boolean, :default => false field :enable_zh_cn, :type => Boolean, :default => true field :default_locale, :default => "zh_tw" field :mobile_on, :type => Boolean, :default => false diff --git a/app/views/admin/sites/preference.html.erb b/app/views/admin/sites/preference.html.erb index e959128..e5531d1 100644 --- a/app/views/admin/sites/preference.html.erb +++ b/app/views/admin/sites/preference.html.erb @@ -185,6 +185,14 @@ +
+ +
+ <%= f.check_box :enable_redirect_index, :class => "toggle-check reset_default_locale", data: {disabled: true} %> +
+
+ diff --git a/config/locales/en.yml b/config/locales/en.yml index 8384a7a..88a5c7f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -422,6 +422,7 @@ en: lang_enabled: Enable Language lang_default: Default Language lang_detection: Enable User Language Detection + redirect_index: Redirect to home if page not found nav_enabled: Enable Sidebar Sub Nav openness: Openness orbitbar_theme: OrbitBar Theme diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3d279de..ed0d5fe 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -429,6 +429,7 @@ zh_tw: icon: 圖示 language: 語系設定 lang_detection: 開啟使用者語系偵測 + redirect_index: 切換語系倒回首頁 lang_enabled: 開啟語系 lang_default: 預設語系 nav_enabled: 開啟側欄導引