<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>里克的自习室 &#187; REST</title>
	<atom:link href="http://railser.cn/blog/tag/rest/feed" rel="self" type="application/rss+xml" />
	<link>http://railser.cn</link>
	<description>关注Ruby和Rails的学习与开发</description>
	<lastBuildDate>Tue, 20 Dec 2011 11:47:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>RESTful的Rails开发，讲讲4Rails.cn的开发心得</title>
		<link>http://railser.cn/blog/rails-on-rest-and-4rails-cn</link>
		<comments>http://railser.cn/blog/rails-on-rest-and-4rails-cn#comments</comments>
		<pubDate>Sun, 20 Jan 2008 09:01:29 +0000</pubDate>
		<dc:creator>里克</dc:creator>
				<category><![CDATA[default]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[ROA]]></category>

		<guid isPermaLink="false">http://railser.cn/archives/rails-on-rest-and-4rails-cn</guid>
		<description><![CDATA[这是一篇笔记。 最近的事情很多很不顺利，不过一切都会过去，并且重新走上 正规的。 前阵子在看《RESTful Web Services》，看得更加迷惑，毕竟是英文书，不太好理解。不过关于REST的理解还是整理了一下。 同时在写一个个人的项目，主要是在开发的过程中保持对编程的感觉（因为没有接到赚钱的项目），还有就是试用新的Rails2.0.2，以及对REST的重新理解。 这个个人的项目是http://4rails.cn，一个招聘信息发布和简历系统。由于目前是个人练习，所以功能上很主观，并未太考虑实用性。而且在正式美化界面前，它属于全人类。 开发4Rails有几个想法： 1、RESTful和ROA 2、Rails2.0.2下的RESTful 3、几个插件的使用 4、实现以前想过但是没做的想法 5、为另一个项目准备 随便写写： 1、RESTful和ROA I hold that everything in the Resource-Oriented Architecture is also RESTful. 在这篇文章里面，比较详细的介绍了REST的概念，但是，普遍的来说，很多文章 对REST的描述都是千篇一律的。那么，《RESTful Web Services》中如何来介绍REST的呢？ 第四章《The Resource-Oriented Architecture》 中讲到：REST不是一个结构，而是一个标准[criteria]，但是这里并不是在说“REST 结构”。而ROA(Resource-Oriented Architecture)才是一个结构，一个RESTful的结构。 在这里，“Oriented”再次出现在眼里，而它出现最多地方的便是“Object Oriented Programming”，计算机教科书里的翻译为“面向对象的程序设计”。那么根据同样的原则，来对ROA理解，可以叫做“面向资源的结构”。 那么Rails2.0.2里面，是如何来实现ROA的呢？ 2、Rails2.0.2下的RESTful 在Rails1.2.x里面就在坚持着RESTful的风格，现在Rails2.0.2更加强调了ROA的结构，特别是在scaffold的生成和routes的设计上。不过，Rails并不是完全的REST，“RESTful”比较合适。而在目前的开发中，更多的是在遵循ROA，来设计“资源”。 在4Rails的这个系统中，资源包括：用户，招聘信息，用户关注的信息，简历，头像。 刚开始对REST感兴趣的时候，经常会想到的问题：“是不是网站的设计都要RESTful”，不。 REST讲究的是ROA的设计，是对网站资源的操作，而很多业务操作，如用户登陆，购买流程，统计结算等等，还是需要传统的设计。RESTful的优点是方便资源的利用。所以，再重新设计一个销售项目的时候，Rails做的是对网站资源和用户资源重新设计，这主要的改进是，对资源的表述更加准确。 比如以前喜欢把用户中心地址设计成"/u/1"，用户的销售商品列表就是"/goods"。 而现在统一的都是"/users/1"，和"/users/1/goods"，当然，这里面避免了的麻烦还很多。 里克：当然，id的使用并不是REST所提倡的，因为它不够直接，而且当id变化的时候（很容易造成变化，比如新老系统的数据整合的时候），就会造成一些问题。我倒是希望Rails能够用slug来代替id，就像wp的Post Slug，或者给出两个方案，默认用id，slug可选。这会成真吗？ 有时候，xxx_id 并不一定代表model关系中的外键关联，它可能是一个判断标准。尤其在REST的view页面的时候。对于需要对其判断权限的访问者，这个id比其他的更重要。 3、插件 4Rails用到了4个插件： will_paginate：分页插件，很好用。 [...]]]></description>
			<content:encoded><![CDATA[<p>这是一篇笔记。</p>
<p>最近的事情很多很不顺利，不过一切都会过去，并且重新走上 正规的。</p>
<p>前阵子在看《RESTful Web Services》，看得更加迷惑，毕竟是英文书，不太好理解。不过关于REST的理解还是整理了一下。</p>
<p>同时在写一个个人的项目，主要是在开发的过程中保持对编程的感觉（因为没有接到赚钱的项目），还有就是试用新的Rails2.0.2，以及对REST的重新理解。</p>
<p>这个个人的项目是<a href="http://4rails.cn" target="_blank">http://4rails.cn</a>，一个招聘信息发布和简历系统。由于目前是个人练习，所以功能上很主观，并未太考虑实用性。而且在正式美化界面前，它属于全人类。</p>
<p>开发4Rails有几个想法：</p>
<blockquote><p> 1、RESTful和ROA</p>
<p>2、Rails2.0.2下的RESTful</p>
<p>3、几个插件的使用</p>
<p>4、实现以前想过但是没做的想法</p>
<p>5、为另一个项目准备</p></blockquote>
<p>随便写写：</p>
<h3>1、RESTful和ROA</h3>
<blockquote><p> I hold that everything in the Resource-Oriented Architecture is also RESTful.</p></blockquote>
<p>在<a href="http://baike.baidu.com/view/1077487.htm" target="_blank">这篇文章</a>里面，比较详细的介绍了REST的概念，但是，普遍的来说，很多文章 对REST的描述都是千篇一律的。那么，《RESTful Web Services》中如何来介绍REST的呢？</p>
<p>第四章《The Resource-Oriented Architecture》 中讲到：REST不是一个结构，而是一个标准[criteria]，但是这里并不是在说“REST 结构”。而ROA(Resource-Oriented Architecture)才是一个结构，一个RESTful的结构。</p>
<p>在这里，“Oriented”再次出现在眼里，而它出现最多地方的便是“<a href="http://baike.baidu.com/view/63596.htm">Object Oriented Programming</a>”，计算机教科书里的翻译为“面向对象的程序设计”。那么根据同样的原则，来对ROA理解，可以叫做“面向资源的结构”。</p>
<p>那么Rails2.0.2里面，是如何来实现ROA的呢？</p>
<h3>2、Rails2.0.2下的RESTful</h3>
<p>在Rails1.2.x里面就在坚持着RESTful的风格，现在Rails2.0.2更加强调了ROA的结构，特别是在scaffold的生成和routes的设计上。不过，Rails并不是完全的REST，“RESTful”比较合适。而在目前的开发中，更多的是在遵循ROA，来设计“资源”。</p>
<p>在4Rails的这个系统中，资源包括：用户，招聘信息，用户关注的信息，简历，头像。</p>
<p>刚开始对REST感兴趣的时候，经常会想到的问题：“是不是网站的设计都要RESTful”，不。</p>
<p>REST讲究的是ROA的设计，是对网站资源的操作，而很多业务操作，如用户登陆，购买流程，统计结算等等，还是需要传统的设计。RESTful的优点是方便资源的利用。所以，再重新设计一个销售项目的时候，Rails做的是对网站资源和用户资源重新设计，这主要的改进是，对资源的表述更加准确。</p>
<p>比如以前喜欢把用户中心地址设计成"/u/1"，用户的销售商品列表就是"/goods"。<br />
而现在统一的都是"/users/1"，和"/users/1/goods"，当然，这里面避免了的麻烦还很多。</p>
<p>里克：当然，id的使用并不是REST所提倡的，因为它不够直接，而且当id变化的时候（很容易造成变化，比如新老系统的数据整合的时候），就会造成一些问题。我倒是希望Rails能够用slug来代替id，就像wp的Post Slug，或者给出两个方案，默认用id，slug可选。这会成真吗？</p>
<p>有时候，xxx_id 并不一定代表model关系中的外键关联，它可能是一个判断标准。尤其在REST的view页面的时候。对于需要对其判断权限的访问者，这个id比其他的更重要。</p>
<h3>3、插件</h3>
<p>4Rails用到了4个插件：</p>
<p>will_paginate：分页插件，很好用。</p>
<p>resource_feeder和simply_helpful：用来实现RSS订阅。不过被大砍了很多代码，因为是针对1.2.x版本的，在2.0.2上会覆盖掉默认的form_form 方法，所以需要改一下。</p>
<p>acts_as_attachment：头像的上传</p>
<p>acts_as_attachment和attachment_fu两个插件会在下一篇博客里好好整理一下，早就知道这两个插件的大名，而且向人吹嘘说是插件排行榜前三位。不过说实话我还没用过呢。嘿嘿。</p>
<pre>
<script type="text/javascript"><!--
google_ad_client = "pub-7545275883969710";
//336x280, 正方形图文
google_ad_slot = "8079527128";
google_ad_width = 336;
google_ad_height = 280;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</pre>
<p>参考文章：<br />
<a href="http://www.ibm.com/developerworks/cn/web/wa-ajaxarch/">Ajax 和 REST，第 1 部分</a><br />
<a href="http://www.ibm.com/developerworks/cn/web/wa-ajaxarch2.html">Ajax 和 REST，第 2 部分</a></p>
]]></content:encoded>
			<wfw:commentRss>http://railser.cn/blog/rails-on-rest-and-4rails-cn/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关注:Rails上的Opensocial实现</title>
		<link>http://railser.cn/blog/opensocial-with-ruby-on-rails</link>
		<comments>http://railser.cn/blog/opensocial-with-ruby-on-rails#comments</comments>
		<pubDate>Tue, 04 Dec 2007 03:11:07 +0000</pubDate>
		<dc:creator>里克</dc:creator>
				<category><![CDATA[default]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[opensocial]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://railser.cn/archives/opensocial-with-ruby-on-rails</guid>
		<description><![CDATA[注：这是opensocial在google code上的视频，经常看可以锻炼下英语 什么是OpenSocial OpenSocial是一套API，具体说是由两种类型的API组成。第一种，REST 形式的API是向Social Network或其他遵循 该协议的应用，发送个人资料，好友，活动和persistence components[?]。第二种，Javascript API是以表单的形式实现第一种的REST应用。 Rails上的OpenSocial 本段译自Google's OpenSocial with Ruby on Rails 根据OpenSocial documentation上的显示，目前OpenSocial开放了2中类型资源：people，一个用户的好友，和activities，这些好友的活动/行为。这种结构正好符合rails对集中资源的理解，在一个user Controller中，我们可以狠容易的得到用户的好友和他们的活动。 OpenSocial的API是按照REST结构设计，但是它并不完全符合Rails的观点，首先，通过URL访问资源的形式并不是Rails的标准形式。其次，它不包含format extension，这意味着你不能直接使用respond_to块。 但是上面两个问题可以通过在routes文件增加一组路由描述和增加一个自定义的mimetype来解决。 下面的路由规则是在描述如何在我们的user_controller中对应OpenSocial 中的people资源的。 &#160; # config/environment.rb Mime::Type.register &#34;application/x-opensocial&#34;, :opensocial &#160; # config/routes.rb map.opensocial_person '/feeds/people/:id', :controller =&#38;gt; 'users', \ :action =&#38;gt; 'show', :format =&#38;gt; 'opensocial',\ :conditions =&#38;gt; &#123;:method =&#38;gt; :get&#125; &#160; map.opensocial_person '/feeds/people/:id', :controller =&#38;gt; [...]]]></description>
			<content:encoded><![CDATA[<pre>
<script type="text/javascript"><!--
google_ad_client = "pub-7545275883969710";
//468x60, 创建于 07-12-3
google_ad_slot = "2874464732";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></pre>
<pre>
<object height="355" width="425"><param name="movie" value="http://www.youtube.com/v/9KOEbAZJTTk&amp;rel=1&amp;border=0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/9KOEbAZJTTk&amp;rel=1&amp;border=0" type="application/x-shockwave-flash" wmode="transparent" height="355" width="425"></embed></object></pre>
<p>注：这是opensocial在google code上的视频，经常看可以锻炼下英语</p>
<h3>什么是OpenSocial</h3>
<p>OpenSocial是一套API，具体说是由两种类型的API组成。第一种，REST 形式的API是向Social Network或其他遵循 该协议的应用，发送个人资料，好友，活动和persistence components[?]。第二种，Javascript API是以表单的形式实现第一种的REST应用。</p>
<h3>Rails上的OpenSocial</h3>
<p>本段译自<a href="http://blog.new-bamboo.co.uk/2007/11/7/opensocial-with-ruby-on-rails" target="_blank">Google's OpenSocial with Ruby on Rails</a><br />
根据<a href="http://code.google.com/apis/opensocial/">OpenSocial documentation</a>上的显示，目前OpenSocial开放了2中类型资源：people，一个用户的好友，和activities，这些好友的活动/行为。这种结构正好符合rails对集中资源的理解，在一个user Controller中，我们可以狠容易的得到用户的好友和他们的活动。<br />
OpenSocial的API是按照REST结构设计，但是它并不完全符合Rails的观点，首先，通过URL访问资源的形式并不是Rails的标准形式。其次，它不包含format extension，这意味着你不能直接使用respond_to块。<br />
但是上面两个问题可以通过在routes文件增加一组路由描述和增加一个自定义的mimetype来解决。<br />
下面的路由规则是在描述如何在我们的user_controller中对应OpenSocial 中的people资源的。</p>
<blockquote>
<pre class="ruby">&nbsp;
<span style="color:#008000; font-style:italic;"># config/environment.rb</span>
<span style="color:#6666ff; font-weight:bold;">Mime::Type</span>.<span style="color:#9900CC;">register</span> <span style="color:#996600;">&quot;application/x-opensocial&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:opensocial</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># config/routes.rb</span>
map.<span style="color:#9900CC;">opensocial_person</span> <span style="color:#996600;">'/feeds/people/:id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> =&amp;gt; <span style="color:#996600;">'users'</span>, \
                            <span style="color:#ff3333; font-weight:bold;">:action</span> =&amp;gt; <span style="color:#996600;">'show'</span>, <span style="color:#ff3333; font-weight:bold;">:format</span> =&amp;gt; <span style="color:#996600;">'opensocial'</span>,\
                            <span style="color:#ff3333; font-weight:bold;">:conditions</span> =&amp;gt; <span style="color:#006600; font-weight:bold;">&#123;</span>:method =&amp;gt; <span style="color:#ff3333; font-weight:bold;">:get</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
map.<span style="color:#9900CC;">opensocial_person</span> <span style="color:#996600;">'/feeds/people/:id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> =&amp;gt; <span style="color:#996600;">'users'</span>,\
                            <span style="color:#ff3333; font-weight:bold;">:action</span> =&amp;gt; <span style="color:#996600;">'update'</span>, <span style="color:#ff3333; font-weight:bold;">:format</span> =&amp;gt; <span style="color:#996600;">'opensocial'</span>, \
                            <span style="color:#ff3333; font-weight:bold;">:conditions</span> =&amp;gt; <span style="color:#006600; font-weight:bold;">&#123;</span>:method =&amp;gt; <span style="color:#ff3333; font-weight:bold;">:put</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
map.<span style="color:#9900CC;">opensocial_person</span> <span style="color:#996600;">'/feeds/people/:id'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> =&amp;gt; <span style="color:#996600;">'users'</span>, \
                             <span style="color:#ff3333; font-weight:bold;">:action</span> =&amp;gt; <span style="color:#996600;">'destroy'</span>, <span style="color:#ff3333; font-weight:bold;">:format</span> =&amp;gt; <span style="color:#996600;">'opensocial'</span>, \
                             <span style="color:#ff3333; font-weight:bold;">:conditions</span> =&amp;gt; <span style="color:#006600; font-weight:bold;">&#123;</span>:method =&amp;gt; <span style="color:#ff3333; font-weight:bold;">:delete</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># app/controllers/users_controller.rb</span>
&nbsp;
respond_to <span style="color:#9966CC; font-weight:bold;">do</span> |format|
  ...
  <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">opensocial</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
</blockquote>
<p>如果上面的比较麻烦，可以<a href="http://blog.nbwd.co.uk/assets/2007/11/7/opensocial_routing.tar.gz">下载</a>作者发的插件。这样你的route文件可以这样写：</p>
<blockquote>
<pre class="ruby">&nbsp;
<span style="color:#008000; font-style:italic;"># config/routes.rb</span>
map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:users</span> <span style="color:#9966CC; font-weight:bold;">do</span> |user|
  user.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:activities</span>
  user.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:relationships</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
map.<span style="color:#9900CC;">opensocial_people</span> <span style="color:#ff3333; font-weight:bold;">:users</span> <span style="color:#9966CC; font-weight:bold;">do</span> |user|
  user.<span style="color:#9900CC;">opensocial_friends</span> <span style="color:#ff3333; font-weight:bold;">:relationships</span>
  user.<span style="color:#9900CC;">opensocial_activities</span> <span style="color:#ff3333; font-weight:bold;">:activities</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
</blockquote>
<p>里克：google上看到的是两种资源，一种持久性方案，下面这个单元就介绍了OpenSocial Container</p>
<h3>OpenSocial Container</h3>
<p>本段整理自<a href="http://www.elctech.com/2007/12/1/opensocial-whats-that" target="_blank">OpenSocial? What's that?</a><br />
<strong>OpenSocial Application</strong><br />
OpenSocial Application使用XML文档来最终render[一个狠程序化的词，我感觉应该不翻译为好]给用户。这个xml包含了metadata，html，和javascript。下面是Last.fm上的OpenSocial应用。<br />
<a href="http://www.last.fm/opensocial/myfavouritemusic.xml">http://www.last.fm/opensocial/myfavouritemusic.xml</a></p>
<blockquote style="overflow: scroll">
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;module<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;moduleprefs</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;My Favorite Music&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;require</span> <span style="color: #000066;">feature</span>=<span style="color: #ff0000;">&quot;opensocial-0.5&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;require</span> <span style="color: #000066;">feature</span>=<span style="color: #ff0000;">'setprefs'</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;require</span> <span style="color: #000066;">feature</span>=<span style="color: #ff0000;">'dynamic-height'</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/moduleprefs<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;content</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;html&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> !<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
<span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;overlord&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;loading&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Loading...<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;updating&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;display:none;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Updating...<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;area&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;lastfmAccount&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;lastfmAccount&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;hadALastfmAccount&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;display:none;&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;strongLinks&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;haveAccountLink&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">&quot;$('setUsername').toggle();_IG_AdjustIFrameHeight();new Effect.ScrollTo('setUsername');return false;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Have a Last.fm account? Click here.<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;setUsername&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;display:none;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;That's me!&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;span</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cancelChangeUsername&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>| <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript:;&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cancel&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>cancel<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/span<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/form<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;placeholder&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;style<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    @import url(http://cdn.last.fm/opensocial/main.5.css);
    @import url(http://cdn.last.fm/opensocial/canvas.1.css);
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/style<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://cdn.last.fm/javascript/lib/prototype.js&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://cdn.last.fm/javascript/lib/scriptaculous.js&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://cdn.last.fm/javascript/source/flashplayer_inline.js&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://cdn.last.fm/javascript/11/flashpreview.js&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://cdn.last.fm/opensocial/lfm.2.js&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  ]]&gt;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/content<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/module<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;</pre>
</blockquote>
<p><strong>OpenSocial Container</strong><br />
OpenSocial Container的设计，是用来给网站提供用户的选择，配置，加强网站的用户应用，尤其在用户属性页面。OpenSocial Container需要能够理解XMl文件格式，并实现OpenSocial Javascript API。</p>
<p><strong>OpenSocial Container如何工作</strong><br />
里克：下面的话还在捉摸<br />
The OpenSocial Container boils down quite simply to an IFRAME with the text of the <content> element from the application's XML dumped in to the body. One difficulty for building a container is dealing with the security risks of exposing cookies set by the "Host Network" to the Application's content, since the Host is doing the embedding. To ensure privacy and a certain degree of security the Container needs to originate from a different domain name than the Host. By doing this the Host/Container (they are the same entity) trick the browser into protecting the Host cookies from the Container's (and thus the Application's) Javascript.</content></p>
<p>The Container also makes extensive use of AJAX to request data from the Host/Container. This is how the Application gets access to the profile, friendship, activities, and persistence information.<br />
<strong>为什么这么做？我们要注意什么？</strong><br />
OpenSocial standardizes social networking APIs. That alone is not particularly novel. But this is Google we're talking about here. With that kind of backing and buzz this may stick. As a developer this means that you only need to learn one API to be able to build social applications. One particularly interesting aspect of the OpenSocial API is the persistence layer. Using this portion of the API a developer can, quite easily, create a full featured interactive application which is entirely self contained in a single static XML file. All of the persistence and communication is handled by the Container and the Host. Now that is cool.</p>
<p>If this takes off like is appears to be poised to do, then we could be in for some excitement akin to the growth and fragmentation of the early social networks; except this will be happing above the social network layer. One interesting possible side effect will be a growth in the popularity of niche social networks. OpenSocial appears to lower the castle walls of the established networks. I expect the crossover in data and user-base between networks will skyrocket as once "proprietary" profile data becomes easily moved and shared.</p>
<h3>下载OpenSocial Container 0.2.0</h3>
<p>ruby script/plugin install</p>
<p>http://opensocial.rubyforge.org/svn/plugin/tags/0_2_0/opensocial_container</p>
<h3>下载OpenSocial Container 0.3.0</h3>
<p>ruby script/plugin install</p>
<p>http://opensocial.rubyforge.org/svn/plugin/tags/0_3_0/opensocial_container</p>
<p>注：<br />
本文将继续整理相关内容，有想法的朋友请留言，万分感谢。<br />
本文有很多东西第一次接触，有不妥的地方，如果您愿意指出帮助我提高，劳烦留言。我会认真查找您的提示。<br />
目前正在看OpenSocial Container 0.2/3.0的源码<br />
林肯公园的歌简直成了我的精神支柱了。</p>
<p>参考资料：<br />
<a href="http://elctech.com/2007/12/3/opensocial-container-0-2-0">OpenSocial Container<br />
0.2.0</a><br />
<a href="http://elctech.com/2007/12/7/opensocial-container-0-3-0">OpenSocial Container 0.3.0</a><br />
<a href="http://www.elctech.com/2007/12/1/opensocial-whats-that">OpenSocial? What's that?</a><br />
<a href="http://blog.new-bamboo.co.uk/2007/11/7/opensocial-with-ruby-on-rails">Google's OpenSocial with Ruby on Rails</a><br />
<a href="http://code.google.com/apis/opensocial/">OpenSocial</a><br />
其他：<br />
<a href="http://www.railsjitsu.com/installing-and-configuring-nginx-and-mongrel-for-rails">Installing and Configuring Nginx and Mongrel for Rails</a><br />
<a href="http://blog.new-bamboo.co.uk/2007/11/20/database-optimization-for-rails-apps">Database Optimization for Rails Apps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://railser.cn/blog/opensocial-with-ruby-on-rails/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

