<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Awlter1 (Gabriel Wang)</title>
    <link>https://ruby-china.org/Awlter1</link>
    <description>To make each day count.</description>
    <language>en-us</language>
    <item>
      <title>再见 Crud 程序员</title>
      <description>&lt;p&gt;&lt;a href="https://copilot.github.com/" rel="nofollow" target="_blank"&gt;https://copilot.github.com/&lt;/a&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Tue, 29 Jun 2021 23:29:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/41429</link>
      <guid>https://ruby-china.org/topics/41429</guid>
    </item>
    <item>
      <title>关于数据库自动生成 log 的问题</title>
      <description>&lt;p&gt;请教各位数据库大佬一个问题&lt;/p&gt;

&lt;p&gt;我们现在有这么一个需求：&lt;/p&gt;

&lt;p&gt;把本地数据库的更新同步到 (写入)salesforce database&lt;/p&gt;

&lt;p&gt;大概的逻辑就是 database tables 有 crud 的 log, 这个 log 会自动写入一个叫 trigger log 的 table, 比如 table_a 的 column_a 更新成了 value_a
然后 rails 定时去处理这个 trigger log, 把需要更新的 column 调接口去更新到 salesforce database&lt;/p&gt;

&lt;p&gt;(这么做是因为：需要记录的是数据库更新的 change log，而不是整个 record，如果用整条 record, 没有更新的 column value 会 overwrite salesforce database）&lt;/p&gt;

&lt;p&gt;问题:
我们数据库的 table 是动态的，并没有一一对应 rails 的 model，所以没法用类似这样基于 activerecord 的 gem(&lt;a href="https://github.com/collectiveidea/audited" rel="nofollow" target="_blank" title=""&gt;https://github.com/collectiveidea/audited&lt;/a&gt;) 去记录这些 crud log
那么想要实现这个 database log → trigger log 的逻辑，有什么比较好的解决办法吗？&lt;/p&gt;

&lt;p&gt;其实大概就是实现
&lt;a href="https://devcenter.heroku.com/articles/writing-data-to-salesforce-with-heroku-connect#understanding-the-trigger-log" rel="nofollow" target="_blank"&gt;https://devcenter.heroku.com/articles/writing-data-to-salesforce-with-heroku-connect#understanding-the-trigger-log&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;我在 Heroku Connect 里面看到了&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--
-- Name: hc_capture_insert_from_row(public.hstore, character varying, text[]); Type: FUNCTION; Schema: salesforce; Owner: postgres
--

CREATE FUNCTION salesforce.hc_capture_insert_from_row(source_row public.hstore, table_name character varying, excluded_cols text[] DEFAULT ARRAY[]::text[]) RETURNS integer
    LANGUAGE plpgsql
    AS $$
        DECLARE
            excluded_cols_standard text[] = ARRAY['_hc_lastop', '_hc_err']::text[];
            retval int;

        BEGIN
            -- VERSION 1 --

            IF (source_row -&amp;gt; 'id') IS NULL THEN
                -- source_row is required to have an int id value
                RETURN NULL;
            END IF;

            excluded_cols_standard := array_remove(
                array_remove(excluded_cols, 'id'), 'sfid') || excluded_cols_standard;
            INSERT INTO "salesforce"."_trigger_log" (
                action, table_name, txid, created_at, state, record_id, values)
            VALUES (
                'INSERT', table_name, txid_current(), clock_timestamp(), 'NEW',
                (source_row -&amp;gt; 'id')::int,
                source_row - excluded_cols_standard
            ) RETURNING id INTO retval;
            RETURN retval;
        END;
        $$;


ALTER FUNCTION salesforce.hc_capture_insert_from_row(source_row public.hstore, table_name character varying, excluded_cols text[]) OWNER TO postgres;

--
-- Name: hc_capture_update_from_row(public.hstore, character varying, text[]); Type: FUNCTION; Schema: salesforce; Owner: postgres
--

CREATE FUNCTION salesforce.hc_capture_update_from_row(source_row public.hstore, table_name character varying, columns_to_include text[] DEFAULT ARRAY[]::text[]) RETURNS integer
    LANGUAGE plpgsql
    AS $$
        DECLARE
            excluded_cols_standard text[] = ARRAY['_hc_lastop', '_hc_err']::text[];
            excluded_cols text[];
            retval int;

        BEGIN
            -- VERSION 1 --

            IF (source_row -&amp;gt; 'id') IS NULL THEN
                -- source_row is required to have an int id value
                RETURN NULL;
            END IF;

            IF array_length(columns_to_include, 1) &amp;lt;&amp;gt; 0 THEN
                excluded_cols := array(
                    select skeys(source_row)
                    except
                    select unnest(columns_to_include)
                );
            END IF;
            excluded_cols_standard := excluded_cols || excluded_cols_standard;
            INSERT INTO "salesforce"."_trigger_log" (
                action, table_name, txid, created_at, state, record_id, sfid, values, old)
            VALUES (
                'UPDATE', table_name, txid_current(), clock_timestamp(), 'NEW',
                (source_row -&amp;gt; 'id')::int, source_row -&amp;gt; 'sfid',
                source_row - excluded_cols_standard, NULL
            ) RETURNING id INTO retval;
            RETURN retval;
        END;
        $$;


ALTER FUNCTION salesforce.hc_capture_update_from_row(source_row public.hstore, table_name character varying, columns_to_include text[]) OWNER TO postgres;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但是这个 pg 的 function 是在 update failure 的时候手动写代码去 call 的，也不是自动 call 的
&lt;a href="https://devcenter.heroku.com/articles/writing-data-to-salesforce-with-heroku-connect#update-failures" rel="nofollow" target="_blank"&gt;https://devcenter.heroku.com/articles/writing-data-to-salesforce-with-heroku-connect#update-failures&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;我猜想 pg 应该有 hook 或者 callback 之类的机制，在 insert or update 的时候去 call 一下上面相应的方法？&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 24 Dec 2020 15:51:27 +0800</pubDate>
      <link>https://ruby-china.org/topics/40738</link>
      <guid>https://ruby-china.org/topics/40738</guid>
    </item>
    <item>
      <title>Docker 官方文档 rails template 有问题</title>
      <description>&lt;p&gt;&lt;a href="https://docs.docker.com/compose/rails/" rel="nofollow" target="_blank"&gt;https://docs.docker.com/compose/rails/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;根据这个文档起一个项目，用的 ruby2.6.2
docker-compose up 已经起来了，也手动创建了数据库，但是好像 db 服务还是会打断后面的逻辑
&lt;img src="https://l.ruby-china.com/photo/2020/32c3b041-b7f3-4fc9-9849-6615e16561a9.png!large" title="" alt=""&gt;
之前解决过一次这个问题，好像跟权限有关
&lt;code&gt;POSTGRES_HOST_AUTH_METHOD: "trust"&lt;/code&gt;这次出现问题后我也加了，还是不行&lt;/p&gt;

&lt;p&gt;诡异的是进到 bash 里 (&lt;code&gt;docker-compose run web /bin/bash&lt;/code&gt;) 是这样的
&lt;img src="https://l.ruby-china.com/photo/2020/cacb982e-0e43-4315-b46c-8d076ef0c3cb.png!large" title="" alt=""&gt;
但问题是刚刚 rake db:create 的时候却没问题哦&lt;/p&gt;

&lt;p&gt;google 下前几页的方法都试了。。
是不是和 pg 13 有关系啊。。&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 26 Nov 2020 17:41:39 +0800</pubDate>
      <link>https://ruby-china.org/topics/40630</link>
      <guid>https://ruby-china.org/topics/40630</guid>
    </item>
    <item>
      <title>Heroku Connect 是怎么做到那么快从 SFDC 同步数据的？</title>
      <description>&lt;p&gt;背景：公司因为各种原因，要我们自己写一个乞丐版的 Heroku Connect&lt;/p&gt;

&lt;p&gt;直奔主题：&lt;/p&gt;

&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/heroku-connect-faq#can-i-synchronize-a-subset-of-data-from-salesforce" rel="nofollow" target="_blank"&gt;https://devcenter.heroku.com/articles/heroku-connect-faq#can-i-synchronize-a-subset-of-data-from-salesforce&lt;/a&gt;
FAQ 说 HC 是把数据从 SFDC 全部取出来的，这个很合理&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2020/1a527994-8ca1-46c5-8dbf-0e2d1ade6f34.png!large" title="" alt=""&gt;
但是，HC 的同步设置这里，最低可以做到 2 分钟同步一次？这个 poll 是这么理解的吗？&lt;/p&gt;

&lt;p&gt;如果是几千万条数据，2 分钟内不可能把数据全部同步完呀。&lt;/p&gt;

&lt;p&gt;看起来 write to SFDC 的 poll 逻辑是，如果正在做更新的话，会停止监测
&lt;img src="https://l.ruby-china.com/photo/2020/ff1de631-044d-4f0c-b072-57e8430a27e5.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Wed, 18 Nov 2020 16:22:45 +0800</pubDate>
      <link>https://ruby-china.org/topics/40590</link>
      <guid>https://ruby-china.org/topics/40590</guid>
    </item>
    <item>
      <title>Rails 6 fails to integrate slick-carousel</title>
      <description>&lt;p&gt;在 stackoverflow 问了问题，还无人问津，哪位大哥有空看一眼呀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/61506916/rails-6-fails-to-integrate-slick-carousel" rel="nofollow" target="_blank"&gt;https://stackoverflow.com/questions/61506916/rails-6-fails-to-integrate-slick-carousel&lt;/a&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 30 Apr 2020 09:01:20 +0800</pubDate>
      <link>https://ruby-china.org/topics/39817</link>
      <guid>https://ruby-china.org/topics/39817</guid>
    </item>
    <item>
      <title>关于 docker 的问题</title>
      <description>&lt;p&gt;&lt;a href="https://docs.docker.com/compose/rails/" rel="nofollow" target="_blank"&gt;https://docs.docker.com/compose/rails/&lt;/a&gt;
我跟着这个教程发现卡在了 apt-get 上&lt;/p&gt;

&lt;p&gt;这个把-pp 去掉后打印的打印&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜  assign_docker docker-compose run web rails new . --force --no-deps --database=postgresql
Starting assign_docker_db_1 ... done
Building web
Step 1/13 : FROM ruby:2.5
 ---&amp;gt; 2a14e515b307
Step 2/13 : RUN apt-get update &amp;amp;&amp;amp; apt-get install -y nodejs postgresql-client
 ---&amp;gt; Running in 88acfd681acb
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://security.debian.org/debian-security buster/updates/main amd64 Packages [180 kB]
Get:4 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;一直卡在这儿，&lt;code&gt;Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;google 了下，docker build apt-get update stuck, 也没有合适的结果。。&lt;/p&gt;

&lt;p&gt;代理开/关，全局/自动，各种情况都试过了。。&lt;/p&gt;

&lt;p&gt;好像是网络哪里出问题了&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Mon, 24 Feb 2020 21:25:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/39533</link>
      <guid>https://ruby-china.org/topics/39533</guid>
    </item>
    <item>
      <title>问一个关于 OS\ObjectSpace 内存的细节问题，求熟悉的朋友来一发解答</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.5.1 :117 &amp;gt; a = 'a' + 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a'+ 'a' + 'a' + 'a' + 'a' + 'a'
 =&amp;gt; "aaaaaaaaaaaaaaaaaaaaaaaa"
2.5.1 :118 &amp;gt; a.size
 =&amp;gt; 24
2.5.1 :119 &amp;gt; ObjectSpace.memsize_of a
 =&amp;gt; 65
2.5.1 :120 &amp;gt; b = 'aaaaaaaaaaaaaaaaaaaaaaaa'
 =&amp;gt; "aaaaaaaaaaaaaaaaaaaaaaaa"
2.5.1 :121 &amp;gt; b.size
 =&amp;gt; 24
2.5.1 :122 &amp;gt; ObjectSpace.memsize_of b
 =&amp;gt; 40
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2019/01caf64b-cb3a-4284-a4b7-37c3239007e5.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;为什么都是 24 size 的字符串，&lt;code&gt;ObjectSpace.memsize_of&lt;/code&gt;的结果不同呢？&lt;/p&gt;

&lt;p&gt;另外，说 RVALUE &amp;gt; 23 bytes 就会 storing any extraneous information – that doesn't fit in the slot – in a different location outside the Ruby heap page -&amp;gt; 指的是 OS heap 吗？而且从上面看，为什么 a 的 size 会大于 40?
&lt;img src="https://l.ruby-china.com/photo/2019/65ff4fed-f554-4403-8ef3-ea5effbce0fd.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;如果是的话，为什么这里在算 ruby memory 的时候还要算上 any external data
&lt;img src="https://l.ruby-china.com/photo/2019/354ee1fa-9d6a-431d-92dc-b0e0a2e92991.png!large" title="" alt=""&gt;
上面两图出自这篇文章
&lt;a href="https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html" rel="nofollow" target="_blank"&gt;https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;显然我看起来是没算这个 any external data 的呀
&lt;img src="https://l.ruby-china.com/photo/2019/d6b1747a-4466-49bb-b645-0a467c929381.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Wed, 10 Jul 2019 21:13:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/38825</link>
      <guid>https://ruby-china.org/topics/38825</guid>
    </item>
    <item>
      <title>异常浮点数的处理</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.3.3 :001 &amp;gt; 51.48 + 12.48 + 11.52
 =&amp;gt; 75.47999999999999 #1
2.3.3 :002 &amp;gt; 51.48 + 77.48 + 71.52
 =&amp;gt; 200.48000000000002 #2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;像这样的浮点数大家都是怎么处理的&lt;/p&gt;

&lt;p&gt;前提&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;不能强制精确到小数点后 N 位 &lt;/li&gt;
&lt;li&gt;最理想的结果就是把连续的 0 以及后面的数字干掉 (#1), 或者合理的补位 (#2)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.3.3 :019 &amp;gt; a
 =&amp;gt; 200.48000000000002
2.3.3 :020 &amp;gt; b
 =&amp;gt; 75.47999999999999
2.3.3 :021 &amp;gt; b.next_float
 =&amp;gt; 75.48
2.3.3 :022 &amp;gt; a.prev_float
 =&amp;gt; 200.48
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;大概用这两个方法？&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 27 Jun 2019 17:52:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/38755</link>
      <guid>https://ruby-china.org/topics/38755</guid>
    </item>
    <item>
      <title>并发情况下无法依赖 cache counter 的问题</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Shelf
  field :books_count
  has_many :books
end

class Book
  belongs_to :shelf, counter_cache: :books_count
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;假设，一个 shelf 最多有 10 本书，现在书架上已有 9 本，shelf.books_count = 9&lt;/p&gt;

&lt;p&gt;现在同时进来两个请求，尝试在 shelfs 上创建一个 book&lt;/p&gt;

&lt;p&gt;在 controller 中 create book 时验证 books_count，但是此时两个请求拿到的都是 9，所以两个请求的验证都会通过，会出现书架上出现 11 本书的情况&lt;/p&gt;

&lt;p&gt;请问下，这种情况下怎么处理比较好呢？redis?&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Sun, 02 Jun 2019 15:35:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/38597</link>
      <guid>https://ruby-china.org/topics/38597</guid>
    </item>
    <item>
      <title>想跟外国朋友聊聊西游记，看维基百科看笑了</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2019/226e1e45-832d-4c8d-9717-97b4bf12ac73.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;以后再也不能直视 Erlang 了&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Tue, 05 Mar 2019 07:52:50 +0800</pubDate>
      <link>https://ruby-china.org/topics/38189</link>
      <guid>https://ruby-china.org/topics/38189</guid>
    </item>
    <item>
      <title>如果在访问一个文件的 url 时触发下载的动作而不是在浏览器中打开</title>
      <description>&lt;p&gt;文件是存在七牛上的，&lt;code&gt;link_to file.name, file.url&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;csv 文件在 chrome 上点击链接是下载，而 safari 是直接打开&lt;/p&gt;

&lt;p&gt;mp4 文件在两个浏览器上都是直接打开的&lt;/p&gt;

&lt;p&gt;有没有什么方法可以在点击链接的时候自动下载，而不是直接在浏览器里打开文件呢？&lt;/p&gt;

&lt;p&gt;不管是用 send_file, 还是 H5 的 download tag，文件都必须得是存在自己服务器上，domain 也是自己的才行吧&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/6756416/rails-link-to-to-download-an-image-immediately-instead-of-opening-it-in-the-br/34257689" rel="nofollow" target="_blank"&gt;https://stackoverflow.com/questions/6756416/rails-link-to-to-download-an-image-immediately-instead-of-opening-it-in-the-br/34257689&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/49736214/force-a-download-to-download-image-instead-of-opening-url-link-to-image" rel="nofollow" target="_blank"&gt;https://stackoverflow.com/questions/49736214/force-a-download-to-download-image-instead-of-opening-url-link-to-image&lt;/a&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Wed, 27 Feb 2019 09:24:00 +0800</pubDate>
      <link>https://ruby-china.org/topics/38157</link>
      <guid>https://ruby-china.org/topics/38157</guid>
    </item>
    <item>
      <title>国外有什么比较活跃的 Ruby 论坛嘛？</title>
      <description>&lt;p&gt;搜了下&lt;/p&gt;

&lt;p&gt;譬如 &lt;a href="https://www.ruby-forum.com" rel="nofollow" target="_blank"&gt;https://www.ruby-forum.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;比 ruby-china 还不活跃。。&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 07 Feb 2019 19:22:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/38090</link>
      <guid>https://ruby-china.org/topics/38090</guid>
    </item>
    <item>
      <title>又是关于 ajax 的问题</title>
      <description>&lt;p&gt;&lt;a href="https://ruby-china.org/topics/37671" rel="nofollow" target="_blank"&gt;https://ruby-china.org/topics/37671&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;上次问过了，结果发现上次的解决方法已经失效了，最近大家碰到了类似的情况吗？&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Wed, 16 Jan 2019 16:31:59 +0800</pubDate>
      <link>https://ruby-china.org/topics/38009</link>
      <guid>https://ruby-china.org/topics/38009</guid>
    </item>
    <item>
      <title>关于新增数据和非主键索引的关系</title>
      <description>&lt;p&gt;新增一条数据时，由于主键索是自增的，主键索引更新就是按顺序在索引树的最右端加一条而已对吧&lt;/p&gt;

&lt;p&gt;那非主键索引有什么顺序吗？（索引模型是 B+）每次新加一行数据非主键索引是怎么更新的呀，如果按某种顺序插到树的某个位置，是不是非主键索引加多了会影响增加和删除数据时的效率？&lt;/p&gt;

&lt;p&gt;另外像这种问题我为什么搜不到呀，感觉是方向错了&lt;/p&gt;

&lt;p&gt;这是我尝试搜索的问题&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.google.com.hk/search?safe=strict&amp;amp;ei=44sfXKWXKMvQ8wWRn7rADQ&amp;amp;q=does+secondary+index+reorder+itself+when+adding+a+new+row&amp;amp;oq=does+secondary+index+reorder+itself+when+adding+a+new+row&amp;amp;gs_l=psy-ab.3...69216.83721..83965...1.0..0.120.4336.22j21......0....1..gws-wiz.......0i7i30j0i13j0i8i7i30j0i7i5i30j0i8i30j0i5i30j33i160.LJ1WeDvkl3s" rel="nofollow" target="_blank"&gt;https://www.google.com.hk/search?safe=strict&amp;amp;ei=44sfXKWXKMvQ8wWRn7rADQ&amp;amp;q=does+secondary+index+reorder+itself+when+adding+a+new+row&amp;amp;oq=does+secondary+index+reorder+itself+when+adding+a+new+row&amp;amp;gs_l=psy-ab.3...69216.83721..83965...1.0..0.120.4336.22j21......0....1..gws-wiz.......0i7i30j0i13j0i8i7i30j0i7i5i30j0i8i30j0i5i30j33i160.LJ1WeDvkl3s&lt;/a&gt;&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Sun, 23 Dec 2018 21:29:28 +0800</pubDate>
      <link>https://ruby-china.org/topics/37935</link>
      <guid>https://ruby-china.org/topics/37935</guid>
    </item>
    <item>
      <title>Working with Unix Processes 的问题</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/b7e15c17-dc39-40f4-ac3a-e399798cb626.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;85 页，请问为什么 Both signal handlers are called？&lt;/p&gt;

&lt;p&gt;另外你们要想在 irb 里操练，要小心点
&lt;img src="https://l.ruby-china.com/photo/2018/b822fc47-6596-4213-9aa7-eda08a2005e3.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;另外，这本书已经很久了，有什么知识点已经更新了话，哪位朋友想起来就提一句吧&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Fri, 30 Nov 2018 16:03:04 +0800</pubDate>
      <link>https://ruby-china.org/topics/37835</link>
      <guid>https://ruby-china.org/topics/37835</guid>
    </item>
    <item>
      <title>active job 序列化 Marshal.dump 出来的字符串报错</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/da4d5fd1-3109-4453-81cd-7a37927e4826.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;Google 了一下&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mperham/sidekiq/issues/3638" rel="nofollow" target="_blank"&gt;https://github.com/mperham/sidekiq/issues/3638&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;发现倒数第二楼好像有解决方法了，但是他的留言我实在是看不懂。。哪位朋友能看懂解释下么？ :)&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Sun, 04 Nov 2018 17:28:08 +0800</pubDate>
      <link>https://ruby-china.org/topics/37727</link>
      <guid>https://ruby-china.org/topics/37727</guid>
    </item>
    <item>
      <title>ajax delete 请求后页面不刷新</title>
      <description>&lt;p&gt;最开始，我用 ajax 发送了一个 delete 请求，遇到了这个问题&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/fe1ba508-c1af-4a48-bf83-4f659d46d03c.png!large" title="" alt=""&gt;
在 destroy action 中 redirect_to 到一个 index 页面，rails 用了 delete 请求而不是 get&lt;/p&gt;

&lt;p&gt;google 了一下，说用 status: 303&lt;/p&gt;

&lt;p&gt;&lt;a href="https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get" rel="nofollow" target="_blank"&gt;https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;带上 303 之后，看 server 确实是用的 get, 也不报错了，该 render 的都 render 了，可就是不刷新页面&lt;/p&gt;

&lt;p&gt;请问这是为什么鸭&lt;/p&gt;

&lt;hr&gt;
&lt;h2 id="上代码和日志："&gt;上代码和日志：&lt;/h2&gt;
&lt;p&gt;edit.js.erb&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$('#confirm_button').click(function() {
  var url = $('.js-submit-delete-section').data('url')

  $.ajax({
    method: 'delete',
    url: url,
  })
})
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="现在workable的代码"&gt;现在 workable 的代码&lt;/h3&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def destroy
  @section.destroy

  ...
  flash[:notice] = "删除成功"
  render js: "window.location = '#{course_sections_path(@course)}'"
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;log&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Started DELETE "/courses/5b582404421aa97728ee4e2f/sections/5b681976421aa9c55b549830" for 127.0.0.1 at 2018-10-25 20:49:56 +0800
Processing by Courses::SectionsController#destroy as */*
....
Started GET "/courses/5b582404421aa97728ee4e2f/sections" for 127.0.0.1 at 2018-10-25 20:49:56 +0800
Processing by Courses::SectionsController#index as HTML
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="最开始有问题的代码"&gt;最开始有问题的代码&lt;/h3&gt;
&lt;p&gt;controller&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def destroy
  @section.destroy

  if params[:destroy_content] &amp;amp;&amp;amp; @section.content.destroy
    flash[:success] = "成功解绑并删除"
  end

  if params[:unbind_course_from_content] &amp;amp;&amp;amp; @section.content.update(course: nil)
    flash[:success] = "成功解绑并转换为直播"
  end

  flash[:notice] = "删除成功"
  redirect_to action: :index
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;log&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Started DELETE "/courses/5b582404421aa97728ee4e2f/sections/5b681970421aa9c55b54982e" for 127.0.0.1 at 2018-10-25 20:51:16 +0800
Processing by Courses::SectionsController#destroy as */*
  Parameters: {"course_id"=&amp;gt;"5b582404421aa97728ee4e2f", "id"=&amp;gt;"5b681970421aa9c55b54982e"}
MONGODB | localhost:27017 | MagNet_development.find | STARTED | {"find"=&amp;gt;"users", "filter"=&amp;gt;{"_id"=&amp;gt;BSON::ObjectId('56a8b4c9feec620985000000')}, "limit"=&amp;gt;1, "
MONGODB | localhost:27017 | MagNet_development.update | SUCCEEDED | 0.0023810000000000003s
Redirected to http://localhost:3000/courses/5b582404421aa97728ee4e2f/sections
Completed 302 Found in 78ms


Started DELETE "/courses/5b582404421aa97728ee4e2f/sections" for 127.0.0.1 at 2018-10-25 20:51:16 +0800

ActionController::RoutingError (No route matches [DELETE] "/courses/5b582404421aa97728ee4e2f/sections"):
  actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
.....
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="尝试用303解决后, 但是页面不刷新"&gt;尝试用 303 解决后，但是页面不刷新&lt;/h3&gt;
&lt;p&gt;controller&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def destroy
    @section.destroy

    if params[:destroy_content] &amp;amp;&amp;amp; @section.content.destroy
      flash[:success] = "成功解绑并删除"
    end

    if params[:unbind_course_from_content] &amp;amp;&amp;amp; @section.content.update(course: nil)
      flash[:success] = "成功解绑并转换为直播"
    end

    flash[:notice] = "删除成功"
    redirect_to action: :index, status: 303
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;log&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Started DELETE "/courses/5b582404421aa97728ee4e2f/sections/5bd1bc8aa33259a591f0a71d" for 127.0.0.1 at 2018-10-25 20:52:33 +0800
Processing by Courses::SectionsController#destroy as */*
  Parameters: {"course_id"=&amp;gt;"5b582404421aa97728ee4e2f", "id"=&amp;gt;"5bd1bc8aa33259a591f0a71d"}
MONGODB | localhost:27017 | MagNet_development.find | STARTED | {"find"=&amp;gt;"users", "filter"=&amp;gt;{"_id"=&amp;gt;BSON::ObjectId('56a8b4c9feec620985000000')}, "limit"=&amp;gt;1, 
MONGODB | localhost:27017 | MagNet_development.update | SUCCEEDED | 0.0015010000000000002s
Redirected to http://localhost:3000/courses/5b582404421aa97728ee4e2f/sections
Completed 303 See Other in 45ms


Started GET "/courses/5b582404421aa97728ee4e2f/sections" for 127.0.0.1 at 2018-10-25 20:52:33 +0800
Processing by Courses::SectionsController#index as */*
  Parameters: {"course_id"=&amp;gt;"5b582404421aa97728ee4e2f"}
MONGODB | localhost:27017 | MagNet_development.find | STARTED | {"find"=&amp;gt;"users", "filter"=&amp;gt;{"_id"=&amp;gt;BSON::ObjectId('56a8b4c9feec620985000000')}, "limit"=&amp;gt;1, 
  Rendered layouts/admin/_main_sidebar.html.slim (100.1ms)
  Rendered layouts/admin/_flash_messages.html.slim (4.7ms)
  Rendered layouts/admin/_main_footer.html.slim (3.0ms)
Completed 200 OK in 1147ms (Views: 1120.4ms)
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>Awlter1</author>
      <pubDate>Wed, 24 Oct 2018 20:45:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/37671</link>
      <guid>https://ruby-china.org/topics/37671</guid>
    </item>
    <item>
      <title>国内有没有不圈钱不做货币只做应的靠谱区块链公司</title>
      <description>&lt;p&gt;主要是公益和区块链结合，不知道现在有没有成熟的方案&lt;/p&gt;

&lt;p&gt;另外要是想做需要花多少钱？&lt;/p&gt;

&lt;p&gt;能不能求各位推荐一下相关公司&lt;/p&gt;

&lt;p&gt;国外有吗？&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Fri, 21 Sep 2018 14:30:04 +0800</pubDate>
      <link>https://ruby-china.org/topics/37527</link>
      <guid>https://ruby-china.org/topics/37527</guid>
    </item>
    <item>
      <title>mongoid (5.2.1) 关于 autobuild 的问题</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Class Apple
  embeds_one :core, autobuild: true
end

Class Core
  field :seed_type, type: String, default: -&amp;gt; { binding.pry; apple }
end
&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apple = Apple.new

apple.core
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;请问 apple 为什么是 nil 呢&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Thu, 06 Sep 2018 19:49:17 +0800</pubDate>
      <link>https://ruby-china.org/topics/37453</link>
      <guid>https://ruby-china.org/topics/37453</guid>
    </item>
    <item>
      <title>&lt;input name="person [names][]" &gt; 设置 value 得到空数组</title>
      <description>&lt;p&gt;有一个清空上传文件的组件，清空后 js 会留下一个&lt;code&gt;&amp;lt;input type="hidden" name="person[names][]" &amp;gt;&lt;/code&gt;，点击保存会给后端一个带有空字符串的数组&lt;code&gt;['']&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;所以，有没有什么发放 params[:names] 的值 是一个空数组 &lt;code&gt;[]&lt;/code&gt; 而不是&lt;code&gt;['']&lt;/code&gt;，google 了一下好像没什么方法，不过还是想来这儿问一下&lt;/p&gt;

&lt;p&gt;不想在后端处理，因为这个是一个组件，如果后端处理的话每个 controller 或 model 都要调整&lt;/p&gt;

&lt;p&gt;活着哪位能想到更好的处理方法吗&lt;/p&gt;</description>
      <author>Awlter1</author>
      <pubDate>Tue, 14 Aug 2018 11:09:48 +0800</pubDate>
      <link>https://ruby-china.org/topics/37325</link>
      <guid>https://ruby-china.org/topics/37325</guid>
    </item>
  </channel>
</rss>
