Skip to content

Commit

Permalink
Merge pull request spree-contrib#35 from joeyjoejoejr/master
Browse files Browse the repository at this point in the history
I fixed the spree 1.0.x routing problem without Rack Middleware
  • Loading branch information
peterberkenbosch committed Feb 23, 2012
2 parents 323ff25 + cb8d779 commit aa22d69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spree/static_content_controller.rb
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions 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

0 comments on commit aa22d69

Please sign in to comment.