<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>hechian (赫謙)</title>
    <link>https://ruby-china.org/hechian</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>複製現有數據後修改某些值後存檔</title>
      <description>&lt;p&gt;那天剛好朋友有問到這樣的需求，不知道大家有沒有什麼其他的解法，丟上來跟大家討論下&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(User.first.dup).update_attributes(user_params)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;嗯，這樣一行就好了 XD&lt;/p&gt;

&lt;p&gt;&lt;code&gt;update_attributes&lt;/code&gt;是一個很酷的東西，不管你給它的是 new record 還是 persisted record，都可以透過&lt;code&gt;update_attributes&lt;/code&gt;來進行數據的建立。&lt;/p&gt;

&lt;p&gt;不知道有沒有別的作法呢？&lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Tue, 25 Jun 2013 11:02:06 +0800</pubDate>
      <link>https://ruby-china.org/topics/11971</link>
      <guid>https://ruby-china.org/topics/11971</guid>
    </item>
    <item>
      <title>佈署後 ruby 的 cpu usage 飆高，請問是怎麼回事</title>
      <description>&lt;p&gt;想請問一下各位會不會跑到這種程度呢 ...
我的主機是 Linode 1024，跑 Ubuntu
用 RVM 跑 Ruby 1.9.2-p290
用 Unicorn + Nginx 跑了大概三個站
每個站各用兩個 Unicorn worker
結果每個 worker 居然 CPU 都在 25% 以上，更有甚者是 30% 以上-_-
主進程每個都 12.3% Orz ...
我都暈了我&lt;/p&gt;

&lt;p&gt;請各位不吝指教，感激&lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Mon, 30 Jul 2012 11:12:37 +0800</pubDate>
      <link>https://ruby-china.org/topics/4635</link>
      <guid>https://ruby-china.org/topics/4635</guid>
    </item>
    <item>
      <title>nginx + unicorn 的 unicorn error 中常有 cache get / miss</title>
      <description>&lt;p&gt;error message 是： &lt;code&gt;cache: [GET /] miss&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;我去 Google 後看到 stackoverflow 上有人說把 production 中 &lt;code&gt;config.action_controller.perform_caching = true&lt;/code&gt; 設定為 &lt;code&gt;false&lt;/code&gt; 就可以了，但是這樣不曉得在效能上是不是會有問題&lt;/p&gt;

&lt;p&gt;想請問一下各位是怎樣配置的？&lt;/p&gt;

&lt;p&gt;謝謝  &lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Tue, 29 May 2012 10:13:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/3535</link>
      <guid>https://ruby-china.org/topics/3535</guid>
    </item>
    <item>
      <title>SCSS 對於 &amp; 的判定</title>
      <description>&lt;p&gt;各位好，我現在有一個很有趣 (個人認為) 的小問題想請教大家&lt;/p&gt;

&lt;p&gt;我也就不囉嗦，直接给各位看 code&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#select_box_year, #select_box_month{
  width:  if(&amp;amp; == "#select_box_year", 80px, 90px);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我想要做到類似的事情，也就是說當我判斷到是 select_box_year 的時候，回傳 80px，否則就是 90px，能這樣做嗎？  &lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Wed, 02 May 2012 17:32:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/3032</link>
      <guid>https://ruby-china.org/topics/3032</guid>
    </item>
    <item>
      <title>想請問關於 Table 的規劃</title>
      <description>&lt;p&gt;各位新年好，我這邊有個小問題想請教大家一下
(希望不介意我此文也貼在 ruby-taiwan 那邊，因為我是在台灣站先發的，且不熟悉大陸用詞，若有看不懂的部分請回應，我會再做編修解釋，感謝。)&lt;/p&gt;

&lt;p&gt;就是我現在遇到了兩個問題：&lt;/p&gt;

&lt;p&gt;1.
我現在有個 Model 叫做 Log，這個 Log 用來記錄 User 的操作，譬如說登入、投票等
而 Log 有欄位：&lt;code&gt;target_type&lt;/code&gt;、&lt;code&gt;target_id&lt;/code&gt;兩個，這個&lt;code&gt;target_type&lt;/code&gt;可能會是&lt;code&gt;"User"&lt;/code&gt;或&lt;code&gt;"Vote"&lt;/code&gt;，而 &lt;code&gt;target_id&lt;/code&gt;就有可能是存放&lt;code&gt;user.id&lt;/code&gt;或者&lt;code&gt;vote.id&lt;/code&gt;了
可是我這樣在取得 Log 的時候，要怎樣透過&lt;code&gt;log.target&lt;/code&gt;去取得目標物件呢？
可以在 Log.rb 中&lt;code&gt;belongs_to&lt;/code&gt;設定什麼來做這個 Mapping 嗎？&lt;/p&gt;

&lt;p&gt;2.
我現在另外一個需求是，我得實作一個投票的系統，可以針對不同的產品來分配不同的表供使用者做投票之用，譬如說我有產品叫做：Water 跟 Cola 兩個，這兩個產品會有不同的表：&lt;strong&gt;VoteForWater&lt;/strong&gt;跟&lt;strong&gt;VoteForColoa&lt;/strong&gt;，那我有沒有辦法透過一個 Model 搭配一個參數 (譬如說是&lt;code&gt;vote.for&lt;/code&gt;) 來讓 Rails 自己儲存到對應的表呢？&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vote.for = "water"; vote.save #=&amp;gt; 儲存到VoteForWater
vote2.for = "cola"; vote2.save #=&amp;gt; 儲存到VoteForCola
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;感謝  &lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Mon, 02 Jan 2012 16:22:54 +0800</pubDate>
      <link>https://ruby-china.org/topics/704</link>
      <guid>https://ruby-china.org/topics/704</guid>
    </item>
    <item>
      <title>弱弱的想請教一下用 Linode 的朋友們，關於配置與效能</title>
      <description>&lt;p&gt;Hi 各位，想請教一下
我現在有一台 Linode 1024 Plan 的主機，上面跑了 Ubuntu 11 64bit
目前裝有&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;Apache (2 個 workers)&lt;/li&gt;
&lt;li&gt;nginx (2 個 workers)&lt;/li&gt;
&lt;li&gt;unicorn (4 個 workers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;目前用 unicorn 的只有一個 web app 而已，可是每個 worker 都吃了 5.x %的內存，在另外一台跑 CentOS 的主機上面卻不會這樣，CentOS 的主機上大約 1.x %左右而已 ... 且跑了 10 個以上的 worker
在 Linode 上內存整個耗盡啦囧"&lt;/p&gt;

&lt;p&gt;想請問下各位用 Linode 的前輩們是怎樣配置的？
尤其是 MySQL 的配置 ... 現在吃了 17% 的內存&lt;/p&gt;</description>
      <author>hechian</author>
      <pubDate>Thu, 22 Dec 2011 18:34:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/564</link>
      <guid>https://ruby-china.org/topics/564</guid>
    </item>
  </channel>
</rss>
