<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>cconev (王佳时)</title>
    <link>https://ruby-china.org/cconev</link>
    <description>试玩 Rails 新手请多指教！</description>
    <language>en-us</language>
    <item>
      <title>求推荐 Mongoi 五星打分 gem</title>
      <description>&lt;p&gt;最好是 ajax 的，能方便调出平均分，各分数的打分人数，还有总打分次数等。&lt;/p&gt;

&lt;p&gt;前不久搜索了一遍，一直没找到能用上的。&lt;/p&gt;</description>
      <author>cconev</author>
      <pubDate>Fri, 21 Sep 2012 10:41:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/5671</link>
      <guid>https://ruby-china.org/topics/5671</guid>
    </item>
    <item>
      <title>不用 gem 写个 timeline widget</title>
      <description>&lt;p&gt;对照看了 RubyChina 的 Github 代码库的 API，和 Twitter 的 user_timeline 是一致的，代码改个字段名称直接就能套用。可是看了国内的微博，多套了一层 statuses，然后我就弄不懂了，如：&lt;/p&gt;

&lt;p&gt;&lt;a href="http://open.t.163.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E7%9A%84%E5%BE%AE%E4%B8%93%E6%A0%8F%E5%88%97%E8%A1%A8%28statuses/user_column_timeline%29&amp;amp;oldid=32679" rel="nofollow" target="_blank"&gt;http://open.t.163.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E7%9A%84%E5%BE%AE%E4%B8%93%E6%A0%8F%E5%88%97%E8%A1%A8%28statuses/user_column_timeline%29&amp;amp;oldid=32679&lt;/a&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Github 项目
  def github_repositories
    return [] if self.github.blank?
    count = 14
    cache_key = "github_repositories:#{self.github}+#{count}+v2"
    items = Rails.cache.read(cache_key)
    if items == nil
      begin
        json = open("https://api.github.com/users/#{self.github}/repos?type=owner&amp;amp;sort=pushed").read
      rescue =&amp;gt; e
        Rails.logger.error("Github Repositiory fetch Error: #{e}")
        items = []
        Rails.cache.write(cache_key, items, :expires_in =&amp;gt; 15.days)
        return items
      end

      items = JSON.parse(json)
      items = items.collect do |a1|
        {
          :name =&amp;gt; a1["name"],
          :url =&amp;gt; a1["html_url"],
          :watchers =&amp;gt; a1["watchers"],
          :description =&amp;gt; a1["description"]
        }
      end
      items = items.sort { |a1,a2| a2[:watchers] &amp;lt;=&amp;gt; a1[:watchers] }.take(count)
      Rails.cache.write(cache_key, items, :expires_in =&amp;gt; 7.days)
    end
    items
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;关键的代码段：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;items = items.collect do |a1|
  {
    :name =&amp;gt; a1["name"],
    :url =&amp;gt; a1["html_url"],
    :watchers =&amp;gt; a1["watchers"],
    :description =&amp;gt; a1["description"]
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;要怎么改改呢？&lt;/p&gt;</description>
      <author>cconev</author>
      <pubDate>Sun, 02 Sep 2012 23:44:28 +0800</pubDate>
      <link>https://ruby-china.org/topics/5323</link>
      <guid>https://ruby-china.org/topics/5323</guid>
    </item>
    <item>
      <title>不改数据库字段的情况下，自定义排序输出</title>
      <description>&lt;p&gt;我在做一个 Slider 功能：
' ids = Configs.postids.split("|").collect { |id| id.to_i }'
'&lt;a href="/posts" class="user-mention" title="@posts"&gt;&lt;i&gt;@&lt;/i&gt;posts&lt;/a&gt; = Post.where(:_id.in =&amp;gt; ids).limit(5)'&lt;/p&gt;

&lt;p&gt;设置 postids 为：
'4|2|1|3|7'&lt;/p&gt;

&lt;p&gt;怎样保证最后数据显示还是按照 4|2|1|3|7 的顺序呢？&lt;/p&gt;</description>
      <author>cconev</author>
      <pubDate>Thu, 30 Aug 2012 17:09:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/5258</link>
      <guid>https://ruby-china.org/topics/5258</guid>
    </item>
    <item>
      <title>counter scope 要怎么写？</title>
      <description>&lt;p&gt;topic.rb 中有一个 hits counter，
&lt;code&gt;counter :hits, :default =&amp;gt; 0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;我想炮制个 &lt;code&gt;high_hits&lt;/code&gt; 出来，没有成功。有人可以指导一下么？
&lt;code&gt;scope :high_likes, desc(:likes_count, :_id)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ruby-china/ruby-china/blob/master/app/models/topic.rb" rel="nofollow" target="_blank"&gt;https://github.com/ruby-china/ruby-china/blob/master/app/models/topic.rb&lt;/a&gt;&lt;/p&gt;</description>
      <author>cconev</author>
      <pubDate>Wed, 22 Aug 2012 20:49:09 +0800</pubDate>
      <link>https://ruby-china.org/topics/5094</link>
      <guid>https://ruby-china.org/topics/5094</guid>
    </item>
  </channel>
</rss>
