一个学习RoR中REST的好范例beast (3/157)

本帖地址: 复制地址

楼主: CMO涔漠

用户形象图片

一个学习RoR中REST的好范例beast


--------------------------------------------------------------------------------

今天发现这个forum的实现基本上使用了RESTful风格。粗看了一下代码,感觉对学习REST有一些帮助,

网址:

http://beast.caboo.se/

源码:

http://svn.techno-weenie.net/projects/beast/trunk/



安装说明:
http://beast.caboo.se/forums/1/topics/381



调用beast.caboo.se 的REST服务的说明:

http://weblog.techno-weenie.net/2006/12/13/taking-ares-out-for-a-test-drive

可以使用curl工具来测试。(一个测试的说明文档)

http://blog.inquirylabs.com/2006/08/04/how-to-use-curl-to-test-restful-rails/

我对REST的理解:REST简化了不同应用(系统)之间的互操作性。而RoR的REST实现则更加简练,更简单,如果几个系统都采用RoR开发(最新的1.2版),系统之间要实现互操作是很简单的。

杂谈:我一直以来个人认为互联网上的url广义的看就相当于一般的C,C++,.JAVA中的函数,而传递给url的参数(?pramA=a&pramB=b),就相当于函数的参数,如果要实现回调,则把一个url当作参数传递过去就好了,当然url上“函数签名(或者叫约定)”远没有本地函数调用那么“安全”,回调方必须了解回调url的约定。rails以前的版本在url中隐含了一些参数信息(/controller/show/1),并且rails内定了不少函数签名规则。而Rails1.2的REST则在HTTP协议的Header中隐含了一些参数或者说语义(POST,GET,PUT,DELETE)。Rails1.2的REST实现 替程序员作了很多工作,使得调用url"函数" 就像调用本地函数一样方便。



回到帖子顶部

1楼[楼主] CMO涔漠

用户形象图片

附:
beast 安装说明:
=======================================
Beast
Beast is the spiffing new forum software from those two terribly clever chaps Josh Goebel and Rick Olson. Rick is already responsible for a very useful Ruby on Rails plug-in called acts_as_versioned and the very promising Mephisto blogweight CMS while Josh has a Rails Wiki called ServerSideWiki under his belt plus the rather useful Pastie.

The aim of Beast is to be a small and straightforward Ruby on Rails forum in less than 500 lines of code.  It's up to 432 at the moment but seems about ready to go.

So, first problem, to get Beast installed on my Windows laptop development machine.

Step 1. svn checkout http://svn.techno-weenie.net/projects/beast/trunk/

You'll probably use Tortoise of course, but you're going to need SVN in line mode shortly.

Step 2. Bring up one of those terribly old-fashioned looking command shells (Start -> Run -> cmd.exe) and go to your new beast folder. Then: rake freeze_edge 

This is needed as Beast uses some of the features in the 'edge' version of Rails, i.e. the version that hasn't been formally released yet.  The main thing it appears to use is the new RESTful routing, of which more some other time.  This command will need svn to be in the path so you may need to append "C:\Program Files\Subversion\bin" to the end of the current path.

Step 3. gem install RedCloth

RedCloth is the Ruby implementation of Textile, a natty text format that can edited easily and translated to and from HTML.  

Step 4: Set up the database.  Grab 'database.example.yml' from the config folder and reformat it for whatever database you're planning to use.  Beast seems to prefer SQLite 2, so I'm going to use that.  So all I'm doing is renaming 'database.example.yml' to 'database.yml'. 

If you don't already have SQLite there are two intermediate steps:

Step 4a: Download SQLite 2 from the SQLite download page and drop the exe, dll and def files in c:\ruby\bin.  Instructions of a sort are on this HowtoUseSQLite page.

Step 4b: Install the ruby library for sqlite: gem install sqlite-ruby.  Matt Griffith has made this feel a lot easier.

Then, at last: rake db:schema:load

Step 5: ruby script/server

This will start WEBrick on port 3000 so you can now access Beast on http://localhost:3000/.
回到帖子顶部

2楼[楼主] CMO涔漠

用户形象图片

Beast :最符合 Lighty 想法的讨论区 
 当我一开始看到 Beast 的时候,我总觉得这是一个奇怪的东西, Beast 只是一个简单到不能再简单的「讨论区」,而且真的没别的了。可是当我开始真正花时间在 survey 他的时候,我发现到这真的是一个把精简 code 的精神发挥到极限的东西,里面的 code 相当的精彩。

我们来看看他的内容,截至目前的 trunk 为止,Controller 504行,Helper 94行,Model 238 行,Library 69行,如果不算 Unit test 一共 905行。一千行以下的讨论区,到底能有什么功能呢?

简单易用的讨论区:因为他就是讨论区,所以一切的功能就是讨论区,不过使用起来感觉蛮好用的。也支援一些文字格式化。 
REST Web API:他是目前 REST 化最彻底的 Rails 套件之一,也延续了 Rails 1.2 REST 最棒的特色,「当你完成一个内部功能的同时,你也顺便写完了 REST Web API」。 
OpenID Support:ㄜ,你没看错,他有 Open ID Support 。 
GetTEXT Support:所以 i18n 解决了。Btw,在我读 Beast code 的同时,我也差不多把 po 档写完了,明后天就可以 release 出来。 
没有做任何缩图上传的机制:没错,你没看错。 Beast 是直接使用 gravatar 的缩图,所以如果你没有 gravatar 的帐号,就注册一个吧。这样的作法虽然奇怪,但是相当的合乎 MarshUP 的想法
仔细观察 Beast 的设计哲学,可以说是「讨论区该有的功能,Beast 一行都不少,除了最重要的功能之外,Beast一行 code 都不多」。不管是自己使用 Beast ,或是看 Beast 里面的 code , Beast 都是相当好的选择。

介绍了Beast,当然简单讲一下怎么安装。

下载 beast 
这里使用 svn 来安装

svn checkout http://svn.techno-weenie.net/projects/beast/trunk

安装 Edge Rails
在刚刚下载下来的svn目录下,打入

rake freeze_edge
安装 RedCloth

gem install RedCloth
修改 config
修改 dayabase.yml 的 production 设定

将 db schema 设定到 db 里面

rake db:schema:load RAILS_ENV=production
如此,启动您的 Rails App 即可。 
回到帖子顶部

3楼

用户形象图片

恩  不错

回到帖子顶部
个人信息
  • 荣誉+3
  • 荣誉+2
  • 荣誉+1
  • 荣誉-1
  • 荣誉-2
  • 荣誉-3
发表留言
  • 文章不错!
  • 精华好文!
  • 支持原创文章!
  • 帖子图文并茂,好!
  • 真知灼见,说得好!
  • 恶意广告
  • 违规内容
  • 严重灌水
  • 重复发帖
  • 标题党
你确定要删除此楼层吗
扣20点经验值