Google sitemap files for Rails projects

后端 未结 6 1972
情深已故
情深已故 2020-12-07 08:13

Is there an easy way to create a sitemaps file for Rails projects? Especially for dynamic sites (such as Stack Overflow for example) there should be a way to dynamically cre

6条回答
  •  鱼传尺愫
    2020-12-07 09:04

    I would recommend that you check out the sitemap_generator gem. It handles all of these issues for you...and really, who wants to mess around authoring XML?

    Here is an example sitemap to show how you use your Rails models and path helpers to generate your sitemap URLs:

    # config/sitemap.rb
    SitemapGenerator::Sitemap.default_host = "http://www.example.com"
    SitemapGenerator::Sitemap.create do
      add '/contact_us'
      Content.find_each do |content|
        add content_path(content), :lastmod => content.updated_at
      end
    end
    

    Then you use Rake tasks to refresh as often as you would like. It really is that simple :)

提交回复
热议问题