Ruby on Rails


23
Mar 10

Ruby: Най-добрите практики

Ruby: Най-добрите практики

Ruby Best Practices”  - Книгата е свободна за сваляне


12
Feb 08

Генериране на Google, Yahoo sitemap.xml в rails сайт

Динамично генериране на sitemap.xml в ruby on rails сайт

controller:

def sitemap
  @posts = Post.find :all
  render :layout => false
end

view:

xml.instruct!
xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
  xml.url do
    xml.loc         "http://www.YourSite.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 => 'home', :action => 'details', :id => post)
      xml.lastmod     w3c_date(post.created_at)
      xml.changefreq  "weekly"
      xml.priority    0.9
    end
  end
end

helper:

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

routes:

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

Добавете Вашият sitemap в Google http://www.google.com/webmasters/sitemap

Get Adobe Flash playerPlugin by wpburn.com wordpress themes