diff --git a/app/controllers/spree/static_content_controller.rb b/app/controllers/spree/static_content_controller.rb index 58c5dded..36e8b9ed 100644 --- a/app/controllers/spree/static_content_controller.rb +++ b/app/controllers/spree/static_content_controller.rb @@ -12,7 +12,7 @@ def show request.path end - unless @page = Spree::Page.visible.find_by_slug(path) + unless @page = Spree::Page.visible.find_by_slug(path.gsub('//','/')) render_404 end end diff --git a/config/routes.rb b/config/routes.rb index 980f8cb2..c7f41309 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,29 @@ -Spree::Core::Engine.routes.append do +class Spree::StaticPage + def self.matches?(request) + path = request.fullpath + count = Spree::Page.visible.where(:slug => path.gsub("//","/")).count + 0 < count + end +end + +class Spree::StaticRoot + def self.matches?(request) + path = request.fullpath.gsub("//","/") + (path == '/') && Spree::Page.visible.find_by_slug(path) + end +end + +Spree::Core::Engine.routes.prepend do namespace :admin do resources :pages end - match '/static/*path', :to => 'static_content#show', :via => :get, :as => 'static' - match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' + constraints(Spree::StaticRoot) do + match '/', :to => 'static_content#show', :via => :get, :as => 'static' + end + + constraints(Spree::StaticPage) do + match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' + end end