From 740693018b605baa8609f1c4b147f17b48a781ac Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 20 May 2011 20:49:48 -0400 Subject: [PATCH] sitemap.xml --- app/controllers/sitemap_controller.rb | 10 ++++++++++ app/models/item.rb | 2 ++ app/views/sitemap/index.xml.haml | 14 ++++++++++++++ config/routes.rb | 2 ++ 4 files changed, 28 insertions(+) create mode 100644 app/controllers/sitemap_controller.rb create mode 100644 app/views/sitemap/index.xml.haml diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb new file mode 100644 index 00000000..3b5c270c --- /dev/null +++ b/app/controllers/sitemap_controller.rb @@ -0,0 +1,10 @@ +class SitemapController < ApplicationController + layout nil + + def index + respond_to do |format| + format.xml { @items = Item.sitemap } + end + end +end + diff --git a/app/models/item.rb b/app/models/item.rb index 3b17d414..f04ce234 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -40,6 +40,8 @@ class Item < ActiveRecord::Base scope :sold_in_mall, where(:sold_in_mall => true) scope :not_sold_in_mall, where(:sold_in_mall => false) + scope :sitemap, select([:id, :name]).order(:id).limit(49999) + # Not defining validations, since this app is currently read-only def nc? diff --git a/app/views/sitemap/index.xml.haml b/app/views/sitemap/index.xml.haml new file mode 100644 index 00000000..ee110b35 --- /dev/null +++ b/app/views/sitemap/index.xml.haml @@ -0,0 +1,14 @@ +!!! XML +%urlset{:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9"} + - for item in @items + %url + %loc http://#{request.host_with_port}#{url_for(item)} + %changefreq monthly + %priority 0.5 + + -# Homepage + %url + %loc= root_url + %changefreq monthly + %priority 1.0 + diff --git a/config/routes.rb b/config/routes.rb index 5e464fcc..b5ff9bd0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,5 +41,7 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/wardrobe' => 'outfits#edit', :as => :wardrobe match '/terms' => 'static#terms', :as => :terms + + match '/sitemap.xml' => 'sitemap#index', :as => :sitemap, :format => :xml end