#コントローラー
class SitemapController < ApplicationController
def sitemap
@entries = Entry.find(:all)
headers["Content-Type"] = "text/xml; charset=utf-8"
respond_to do |format|
format.xml {render :layout => false}
end
end
end
#view(sitemap.xml.builder)
xml.instruct!
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") do
xml.url do
xml.loc(url_for(:controller => :entries, :only_path => false))
end
@entries.each do |entry|
xml.url do
xml.loc(url_for(:controller => :entries, :action => :show, :id => entry.id, :only_path => false))
end
end
end
#routes.rb
map.xml 'sitemap.xml' , :controller => 'sitemap', :action => 'sitemap'
参考
http://higelog.brassworks.jp/?p=56
0 件のコメント:
コメントを投稿