Rails sitemap generator

Controller:

  def sitemap 
    @posts = Post.find :all, :conditions => {:private => false}
    respond_to do |format|
      format.xml  { render :layout => false }
    end    
  end

Helper:
  def w3c_date(date)
    date.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00")
  end

View: sitemap.xml.builder
xml.instruct!

xml.urlset 
  "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9",
  "xsi:schemaLocation"=>"http://www.sitemaps.org/schemas/sitemap/0.9
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd", 
  "xmlns"=>"http://www.sitemaps.org/schemas/sitemap/0.9" do
  xml.url do
    xml.loc         "http://www.sharesnippets.com"
    xml.lastmod     w3c_date(Time.now)
    xml.changefreq  "always"
  end

  @posts.each do |post|
    xml.url do
      xml.loc         url_for(:only_path => false, :controller => 'post', :action => 'show', :id => post.id)
      xml.lastmod     w3c_date(post.created_at)
      xml.changefreq  "weekly"
      xml.priority    "0.9"
    end
  end
end


route:
  map.connect "sitemap.xml", :controller => "home", :action => "sitemap"  

subversion and rails project

svn remove log/* --force
svn commit -m "removing all logs from subversion"
svn propset svn:ignore "*.log" log/ --force
svn update log/
svn commit -m "Ignoring all files in /log/ ending in .log"
svn propset svn:ignore "*" tmp/sessions tmp/cache tmp/sockets
svn commit -m "Ignoring all files in /tmp/"
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content"

Rails multiple site application theme managment

  before_filter :get_site
  attr_reader :site
  theme :get_theme, :get_theme_site
 
 
  def get_site
    url = request.domain(request.subdomains.size + (request.subdomains.first == 'www' ? 0 : 1))
    @site ||= Site.find_by_url(url) || Site.find(:first, :order => 'id')
  end
 
  def get_theme
    site.theme
  end
 
  def get_theme_site
    site.id.to_s
  end

Още