最近花了一些时间改造公司的网站(EQV2),这个网站是一个偏重内容和设计的信息类主站,并没有太多功能性的要求,所以在使用Ruby on Rails开发这个网站的时候,尝试了一些之前涉及不多的技术。最初这个网站利用Radiant(RoR的开源CMS系统)搭建,考虑到没有专门的技术人员来管理和研究Radiant,而且和我们自己的系统平台的集成也会有些麻烦,最终决定放弃这把牛刀,仅仅做一个简单而且结构清晰的网站就OK。

我简单列一下这次改造过程中的一些比较典型的处理方法和技术:

* Formtastic + nifty_scaffold
用这两招可以方便的产生后台的CRUD管理部分,不知道为什么我第一反应没有使用ActiveScaffold,可能是从Rails2.3+以后Denny老说使用起来有问题有冲突,我就本能的绕开它了。
参考: http://asciicasts.com/episodes/184-formtastic-part-1

* feedzirra + whenever
feedzirra是一个方便易用的RSS分析器,很不错,结合whenever就可以自动更新源RSS,在我们的系统中我用它们更新Blog中的内容到网站上面来。
参考: http://github.com/pauldix/feedzirra
http://github.com/javan/whenever/

* cas
7哥搭建了一个idp_cas的server,我就结合这个做了一个单点登录的控制,用来对后台内容管理做权限控制。这个方案很轻量级,避免了直接集成复杂的idp用户验证系统。

* Routing
此次最想突出介绍的是ROR的Routing机制,强大的Routing可以将URL改写成任何形式,以适应SEO的需要,同时也可以做坏链的容错处理。很好很强大,就是不知道效率如何,这个有待进一步熟悉。

* caches_page
由于本次改造过程中主要涉及内容性质的View,所以我只进行了Page Cache,Rails的Cache方法也很简单易用,我稍后会做一个较为详细的总结,讨论一下各种Cache的问题。

此次改造的重点是网站结构和UI/UE的设计,Noah和Buzz主要负责这方面的工作,正因为他们出色的工作成果才使得EQV2顺利按期交付。

There are a number of ways of parsing an RSS feed in Ruby, but one of the best is a gem called Feedzirra. The main advantage of Feedzirra is its speed; it parses feeds very quickly, but it is also useful as it can parse many different types of feed.

To install Feedzirra we first need to make sure that

1
http://gems.github.com

is in our list of gem sources. If not we’ll need to add it.

gem sources -a http://gems.github.com

Now we can install the gem:

sudo gem install pauldix-feedzirra

Notice: When I was installing the gem, there are several libs needed, including libcurl4-gnutls-dev libcurl3-gnutls libxslt1-dev, you may not meet this issue, it’s not a big deal, just install what it rely on. Several dependencies will also be installed alongside the gem. Once everything’s installed we’ll need to add a reference to the gem in our application’s /config/environment.rb file.

config.gem "pauldix-feedzirra", :lib => "feedzirra", :source => "http://gems.github.com"

That’s it. We’re ready to start parsing RSS feeds in our application.

Getting start:
Assume that, you’ve got a model to store the feed content which is fetched by the parser, so the model should be like :

class FeedEntry < ActiveRecord::Base
  def self.update_from_feed(feed_url)
    feed = Feedzirra::Feed.fetch_and_parse(feed_url)
    add_entries(feed.entries)
  end

  private
  def self.add_entries(entries)
    entries.each do |entry|
      unless exists? :guid => entry.id
        create!(
          :name         => entry.title,
          :summary      => entry.summary,
          :url          => entry.url,
          :published_at => entry.published,
          :guid         => entry.id
        )
      end
    end
  end
end

A more detailed manual is here!

© 2011 Refactoring Thoughts Suffusion theme by Sayontan Sinha
普人特福的博客cnzz&51la for wordpress,cnzz for wordpress,51la for wordpress