forked from spree-contrib/spree_static_content
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spree-contrib#35 from joeyjoejoejr/master
I fixed the spree 1.0.x routing problem without Rack Middleware
- Loading branch information
Showing
2 changed files
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |