This is how I generate my google sitemap for my sites: :).
1. First, create a controller named xml.
2. Then, for example for the tag links create this method in xml_controller.rb
# in xml_controller.rb
def tags
@tags = Tag.find(:all, :conditions=> "approved = true")
end
def tags
@tags = Tag.find(:all, :conditions=> "approved = true")
end
3. In the Views/xml create a tag.rxml file:
# in views/xml/tags.rxhml
xml.instruct! :xml, :version=>"1.0"
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9"){
@tags.each do |tag|
xml.url{
xml.loc(tag_url(:tag=>tag))
xml.priority(0.9)
xml.changefreq("weekly")
}
end
}
xml.instruct! :xml, :version=>"1.0"
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9"){
@tags.each do |tag|
xml.url{
xml.loc(tag_url(:tag=>tag))
xml.priority(0.9)
xml.changefreq("weekly")
}
end
}
4. In routes.rb add the route:
#routes.rb
map.tag ‘tag/:tag’, :controller=>"tag", :action=>"view"
map.connect ‘tags.xml’, :controller => "xml", :action => "tags"
map.tag ‘tag/:tag’, :controller=>"tag", :action=>"view"
map.connect ‘tags.xml’, :controller => "xml", :action => "tags"
5. Type localhost:300x/tags.xml
This is the magical code that I use :). I just create a separate method for each model (products, categories, etc).

RECENT COMMENTS