<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>zhaopei (赵配)</title>
    <link>https://ruby-china.org/zhaopei</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>mac 上安装 therubyracer -v '0.12.2' 安装问题</title>
      <description>&lt;p&gt;mac 上安装 therubyracer 0.12.2  依赖于 libv8 3.16.14.13
安装日志如下：
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.&lt;/p&gt;

&lt;p&gt;current directory: /usr/local/lib/ruby/gems/2.3.0/gems/therubyracer-0.12.2/ext/v8
/usr/local/opt/ruby/bin/ruby -r ./siteconf20160401-35470-1bzsbrk.rb extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... yes
checking for main() in -lv8... yes
creating Makefile&lt;/p&gt;

&lt;p&gt;To see why this extension failed to compile, please check the mkmf.log which can be found here:&lt;/p&gt;

&lt;p&gt;/usr/local/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0/therubyracer-0.12.2/mkmf.log&lt;/p&gt;

&lt;p&gt;current directory: /usr/local/lib/ruby/gems/2.3.0/gems/therubyracer-0.12.2/ext/v8
make "DESTDIR=" clean&lt;/p&gt;

&lt;p&gt;current directory: /usr/local/lib/ruby/gems/2.3.0/gems/therubyracer-0.12.2/ext/v8
make "DESTDIR="
compiling accessor.cc
clang: warning: argument unused during compilation: '-rdynamic'
In file included from accessor.cc:1:
In file included from ./rr.h:4:
/usr/local/include/v8.h:360:33: error: use of undeclared identifier 'nullptr'
  V8_INLINE MaybeLocal() : val_(nullptr) {}
                                ^
/usr/local/include/v8.h:367:51: error: use of undeclared identifier 'nullptr'
  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
                                                  ^
/usr/local/include/v8.h:371:29: error: use of undeclared identifier 'nullptr'
    out-&amp;gt;val_ = IsEmpty() ? nullptr : this-&amp;gt;val_;
                            ^
/usr/local/include/v8.h:437:50: error: use of undeclared identifier 'nullptr'
  bool IsFirstPass() const { return callback_ != nullptr; }
                                                 ^
/usr/local/include/v8.h:808:42: error: use of undeclared identifier 'nullptr'
  V8_INLINE Global() : PersistentBase(nullptr) {}
                                         ^
/usr/local/include/v8.h:833:18: error: use of undeclared identifier 'nullptr'
    other.val_ = nullptr;
                 ^
/usr/local/include/v8.h:845:18: error: use of undeclared identifier 'nullptr'
      rhs.val_ = nullptr;
                 ^
/usr/local/include/v8.h:1110:52: error: use of undeclared identifier 'nullptr'
                            ScriptOrigin* origin = nullptr));
                                                   ^
/usr/local/include/v8.h:1113:30: error: use of undeclared identifier 'nullptr'
      ScriptOrigin* origin = nullptr);
                             ^
/usr/local/include/v8.h:3242:36: error: use of undeclared identifier 'nullptr'
    return NewInstance(context, 0, nullptr);
                                   ^
/usr/local/include/v8.h:4457:57: error: use of undeclared identifier 'nullptr'
      experimental::FastAccessorBuilder* fast_handler = nullptr,
                                                        ^
/usr/local/include/v8.h:4473:57: error: use of undeclared identifier 'nullptr'
      experimental::FastAccessorBuilder* fast_handler = nullptr);
                                                        ^
/usr/local/include/v8.h:7292:27: error: use of undeclared identifier 'nullptr'
  if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
                          ^
In file included from accessor.cc:1:
./rr.h:358:39: error: no member named 'ScriptData' in namespace 'v8'
class ScriptData : public Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt; {
                                  ~~&lt;del&gt;^
./rr.h:358:51: error: expected class name
class ScriptData : public Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt; {
                                                  ^
./rr.h:360:21: error: no type named 'ScriptData' in namespace 'v8'; did you mean simply 'ScriptData'?
  inline ScriptData(v8::ScriptData* d) : Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt;(d) {};
                    ^&lt;/del&gt;~~~~~~~~~~~
                    ScriptData
./rr.h:358:7: note: 'ScriptData' declared here
class ScriptData : public Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt; {
      ^
./rr.h:360:54: error: no member named 'ScriptData' in namespace 'v8'
  inline ScriptData(v8::ScriptData* d) : Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt;(d) {};
                                                 ~~~~^
./rr.h:360:65: error: expected class member or base class name
  inline ScriptData(v8::ScriptData* d) : Pointer&lt;a rel="nofollow" target="_blank"&gt;v8::ScriptData&lt;/a&gt;(d) {};
                                                                ^
./rr.h:360:65: error: expected '{' or ','
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [accessor.o] Error 1&lt;/p&gt;

&lt;p&gt;make failed, exit code 2&lt;/p&gt;

&lt;p&gt;Gem files will remain installed in /usr/local/lib/ruby/gems/2.3.0/gems/therubyracer-0.12.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0/therubyracer-0.12.2/gem_make.out&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Fri, 01 Apr 2016 19:07:50 +0800</pubDate>
      <link>https://ruby-china.org/topics/29526</link>
      <guid>https://ruby-china.org/topics/29526</guid>
    </item>
    <item>
      <title>Rails 中用 Mongoid  的 map_reduce 中 float 类型相加问题，</title>
      <description>&lt;pre class="highlight ruby"&gt;&lt;code&gt; &lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%Q{
      function() {
        emit(this.userinfo.id, {totalPrice: this.paycost, profit: this.profit, count: 1})
      }
    }&lt;/span&gt;
    &lt;span class="n"&gt;mapStatistic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%Q{
      function() {
        emit(this.userinfo_id, {totalPrice: this.total_price, profit: this.profit, count: 1})
      }
    }&lt;/span&gt;
    &lt;span class="n"&gt;reduce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%Q{
      function(key, values) {
        profit = 0.0;
        income = 0.0;
        count = 0;
        incomes = []
        profits = []
        values.forEach(function(value) {
           income += value.totalPrice;
           profit += value.profit;
           count += value.count;
        });
        return {profit: profit, income: income, count: count}
      }
    }&lt;/span&gt;

&lt;span class="n"&gt;statistics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;OrderStatistic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="ss"&gt;:complete_date&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$gte"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;startDate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"$lte"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;endDate&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;:userinfo_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="vi"&gt;@current_user.userinfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;map_reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mapStatistic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:inline&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt; &lt;span class="s2"&gt;"0000000statistic=======&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;statistics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inspect&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;==sCount=&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;sCount&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;日志打印出来是 1111111statistic======={"_id"=&amp;gt;"564a90a903d0b85d0a000000", "value"=&amp;gt;{"profit"=&amp;gt;38110.0, "income"=&amp;gt;NaN, "count"=&amp;gt;499.0}}
income =&amp;gt; NaN  如何 total_price 小数点保留 2 位的相加后有问题，profit 也是 float，小数点后面没有有效位没有问题。&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Thu, 03 Dec 2015 18:20:42 +0800</pubDate>
      <link>https://ruby-china.org/topics/28268</link>
      <guid>https://ruby-china.org/topics/28268</guid>
    </item>
    <item>
      <title>ActiveResource 如何接合 Devise 认证</title>
      <description>&lt;p&gt;activeResource 要映射远程的 model，但是远程的控制器有 devise 的认证，如何处理？&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Tue, 01 Dec 2015 11:37:03 +0800</pubDate>
      <link>https://ruby-china.org/topics/28247</link>
      <guid>https://ruby-china.org/topics/28247</guid>
    </item>
    <item>
      <title>Faker 如何自定义本地语言文件？或者覆盖原来的语言文件</title>
      <description>&lt;p&gt;github 的文档中这样写：&lt;/p&gt;

&lt;p&gt;Customization&lt;/p&gt;

&lt;p&gt;Since you may want to make addresses and other types of data look different depending on where in the world you are (US postal codes vs. UK postal codes, for example), Faker uses the I18n gem to store strings (like state names) and formats (US postal codes are NNNNN while UK postal codes are AAN NAA), allowing you to get different formats by switching locales. Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.&lt;/p&gt;

&lt;p&gt;If your locale doesn't already exist, create it in the \lib\locales\ directory and you can then override or add elements to suit&lt;/p&gt;

&lt;p&gt;en-au-ocker:
  faker:
    name:
      # Existing faker field, new data
      first_name: [Charlotte, Ava, Chloe, Emily]
      # New faker fields
      ocker_first_name: [Bazza, Bluey, Davo, Johno, Shano, Shazza]
      region: [South East Queensland, Wide Bay Burnett, Margaret River, Port Pirie, Gippsland, Elizabeth, Barossa]&lt;/p&gt;

&lt;p&gt;我在本地的 config/environments/test.rb 中加入了 Faker::Config.locale = 'zh-HK'  然后创建 lib/locales/zh-HK.yml 文件
zh-HK.yml 文件如下图
&lt;img src="https://l.ruby-china.com/photo/2015/2c2d33bb94c2e039f6bba7d8e917d8a5.png" title="" alt=""&gt;
执行 rails console test 后&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2015/85b5ae09be30bc422cff8428d11656b9.png" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;显示是 zh-HK，但是生成的 name 是英文的，不知道什么原因？&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Wed, 28 Oct 2015 18:35:35 +0800</pubDate>
      <link>https://ruby-china.org/topics/27874</link>
      <guid>https://ruby-china.org/topics/27874</guid>
    </item>
    <item>
      <title>ActiveResource 已经不更新了，现在换成其他的什么了？</title>
      <description>&lt;p&gt;activeResource 用的人可不少，现在都不更新，又换成其他新的 gem 包了，还是？&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Tue, 27 Oct 2015 18:57:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/27853</link>
      <guid>https://ruby-china.org/topics/27853</guid>
    </item>
    <item>
      <title>在 RailsGuides 里有个 Active Record Query Interface 的一个问题</title>
      <description>&lt;p&gt;页面里有个这样的写法&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"orders_count = ?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:orders&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我在调用时却显示&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArgumentError: wrong number of arguments (2 for 1)
    from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0/lib/mongoid/criteria.rb:449:in `where'
    from (eval):2:in `where'
    from (irb):23
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;什么原因？，怎么用代？的传递参数，&lt;/p&gt;</description>
      <author>zhaopei</author>
      <pubDate>Tue, 06 Oct 2015 16:28:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/27558</link>
      <guid>https://ruby-china.org/topics/27558</guid>
    </item>
  </channel>
</rss>
