<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>zouyu (邹鱼)</title>
    <link>https://ruby-china.org/zouyu</link>
    <description>红尘旧梦里 连走路都小心翼翼</description>
    <language>en-us</language>
    <item>
      <title>Homebrew 中的 formula 如果硬要翻译，是不是翻译为 “配方” 比较合理？</title>
      <description>&lt;p&gt;如题&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 20 Dec 2018 09:34:12 +0800</pubDate>
      <link>https://ruby-china.org/topics/37920</link>
      <guid>https://ruby-china.org/topics/37920</guid>
    </item>
    <item>
      <title>Bundler 有提供 remove gem 的命令吗？</title>
      <description>&lt;p&gt;看了一下 bundler 的文档，好像没有提供从 Gemfile 文件中移除 gem 的命令。&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Sun, 16 Sep 2018 16:19:17 +0800</pubDate>
      <link>https://ruby-china.org/topics/37493</link>
      <guid>https://ruby-china.org/topics/37493</guid>
    </item>
    <item>
      <title>时间啊过的真快</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/27dce566-1e86-4b0c-8e67-458bfc99d67f.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Mon, 13 Aug 2018 12:06:51 +0800</pubDate>
      <link>https://ruby-china.org/topics/37320</link>
      <guid>https://ruby-china.org/topics/37320</guid>
    </item>
    <item>
      <title>大家都去哪里获取信息？</title>
      <description>&lt;p&gt;如题&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;如何获取新闻咨询类信息&lt;/li&gt;
&lt;li&gt;如何获取技术类信息&lt;/li&gt;
&lt;li&gt;如何获取有意思的东西&lt;/li&gt;
&lt;/ol&gt;

&lt;hr&gt;

&lt;ol&gt;
&lt;li&gt;各种新闻类客户端，装了又卸载了&lt;/li&gt;
&lt;li&gt;B 站也是如此&lt;/li&gt;
&lt;li&gt;直播 app 也是如此&lt;/li&gt;
&lt;/ol&gt;

&lt;hr&gt;

&lt;p&gt;我大约是范了一种，不知道自己想要什么信息，但是知道自己不想要什么的病吧！&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Tue, 17 Jul 2018 10:55:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/37174</link>
      <guid>https://ruby-china.org/topics/37174</guid>
    </item>
    <item>
      <title>如下，有比这个优雅的方式吗</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;param[:type_id] = if params[:thirdCategory].present?
                     params[:thirdCategory]
                   elsif params[:secondCategory].present?
                     params[:secondCategory]
                   elsif params[:topCategory].present?
                     params[:topCategory]
                   end
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 05 Jul 2018 11:30:33 +0800</pubDate>
      <link>https://ruby-china.org/topics/37102</link>
      <guid>https://ruby-china.org/topics/37102</guid>
    </item>
    <item>
      <title>(转) Rails 中如何处理异常！</title>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Exception 和 StandardError 的区别&lt;br&gt;
&lt;a href="https://blog.rebased.pl/2016/11/07/api-error-handling.html" rel="nofollow" target="_blank"&gt;https://blog.rebased.pl/2016/11/07/api-error-handling.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;建议在 rails 中全局捕获异常，这个样的话，不会出现在 action 中一坨一坨 begin rescue 的代码&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;应该捕获的是你应用产生的异常。PS，个人认为绝大部分异常来自于数据输入和网络请求&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;想要全局捕获异常，在 action 中就要主动抛出或者调用能抛出异常的方法 例如用 save! 取代 save&lt;br&gt;
&lt;a href="https://blog.rebased.pl/2016/11/07/api-error-handling.html" rel="nofollow" target="_blank"&gt;https://blog.rebased.pl/2016/11/07/api-error-handling.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/rails-ember-beyond/error-handling-in-rails-the-modular-way-9afcddd2fe1b" rel="nofollow" target="_blank"&gt;https://medium.com/rails-ember-beyond/error-handling-in-rails-the-modular-way-9afcddd2fe1b&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;</description>
      <author>zouyu</author>
      <pubDate>Mon, 25 Jun 2018 15:46:56 +0800</pubDate>
      <link>https://ruby-china.org/topics/37042</link>
      <guid>https://ruby-china.org/topics/37042</guid>
    </item>
    <item>
      <title>继承 Model 的类不能重新定义 initialize 方法吗？</title>
      <description>&lt;p&gt;Category 是一个 model&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class C1 &amp;lt; Category
   def initialize
   end
end
C1.new报如下错误
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/b16a7d76-a3d4-4f7c-a235-7949bc868042.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Mon, 28 May 2018 11:09:30 +0800</pubDate>
      <link>https://ruby-china.org/topics/36836</link>
      <guid>https://ruby-china.org/topics/36836</guid>
    </item>
    <item>
      <title>这两种中断 redirect_to 的方式有区别吗</title>
      <description>&lt;p&gt;一&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;redirect_to root_url and return 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;二&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return redirect_to root_url
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>zouyu</author>
      <pubDate>Fri, 11 May 2018 18:13:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/36756</link>
      <guid>https://ruby-china.org/topics/36756</guid>
    </item>
    <item>
      <title>Rails 5.2 中的 secret_key_base</title>
      <description>&lt;p&gt;当 env 为 development 和 test 时使用，如下方式生成&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Digest::MD5.hexdigest self.class.name
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如果非以上两种方式，首先在 &lt;strong&gt;ENV["SECRET_KEY_BASE"]&lt;/strong&gt;查找。&lt;/p&gt;

&lt;p&gt;获取方式&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rails.application.secret_key_base
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://github.com/rails/rails/pull/30067" rel="nofollow" target="_blank" title=""&gt;使用 credentials 来设置敏感配置信息&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下图为源码：
&lt;img src="https://l.ruby-china.com/photo/2018/255c2eab-2b6a-4aca-901e-446aa6bf45ee.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 10 May 2018 13:26:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/36746</link>
      <guid>https://ruby-china.org/topics/36746</guid>
    </item>
    <item>
      <title>fixtures 中加入的数据不走 model 中定义的 validates?</title>
      <description>&lt;p&gt;如题：在 fixtures 中加入的数据，不走 model 定义的 validates，看到几篇文章说，rails 假定 fixtures 中的数据都是合法的。请问，有没有官方的说明？&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Wed, 11 Apr 2018 10:18:14 +0800</pubDate>
      <link>https://ruby-china.org/topics/35422</link>
      <guid>https://ruby-china.org/topics/35422</guid>
    </item>
    <item>
      <title>才发现 续行符 \ 也能用在方法中</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/261ea6a0-0b7d-40ca-a40f-d363ca1721c6.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 29 Mar 2018 10:30:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/35355</link>
      <guid>https://ruby-china.org/topics/35355</guid>
    </item>
    <item>
      <title>GitHub 居然能检测、提醒 Gemfile 中定义的 gem 的漏洞</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/937f2ddd-b869-4850-a06d-c7cfbe66f1d3.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Fri, 23 Mar 2018 11:57:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/35310</link>
      <guid>https://ruby-china.org/topics/35310</guid>
    </item>
    <item>
      <title>2018年 薪资</title>
      <description>&lt;p&gt;最近看到几个站内招聘的，发现待遇低了不少。是今年整个行业形势不行？还是别的什么原因呀？&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Tue, 27 Feb 2018 21:53:14 +0800</pubDate>
      <link>https://ruby-china.org/topics/35100</link>
      <guid>https://ruby-china.org/topics/35100</guid>
    </item>
    <item>
      <title>create 创建记录时是一次提交还是多次提交到数据库</title>
      <description>&lt;p&gt;如题： &lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model.create([{name: 'test1'},   {name: 'test'}])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;使用这种方式创建多条记录时，是一次提交到数据库还是多次？&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 16 Feb 2017 12:16:41 +0800</pubDate>
      <link>https://ruby-china.org/topics/32314</link>
      <guid>https://ruby-china.org/topics/32314</guid>
    </item>
    <item>
      <title>当 public 目录下存在 index.html 时路径请求问题</title>
      <description>&lt;p&gt;在 Rails 开发环境下 (rails  server 启动)
此时，如果 public 目录下有 index.html。当访问路径如下时：
&lt;a href="http://localhost:3000/" rel="nofollow" target="_blank"&gt;http://localhost:3000/&lt;/a&gt;
&lt;a href="http://localhost:3000/index" rel="nofollow" target="_blank"&gt;http://localhost:3000/index&lt;/a&gt;
&lt;a href="http://localhost:3000/index.html" rel="nofollow" target="_blank"&gt;http://localhost:3000/index.html&lt;/a&gt;
为什么会优先访问 public/index.html?&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Fri, 20 May 2016 22:55:30 +0800</pubDate>
      <link>https://ruby-china.org/topics/30079</link>
      <guid>https://ruby-china.org/topics/30079</guid>
    </item>
    <item>
      <title>使用 Unicorn 时可以使用 unicorn-worker-killer 这个 Gem 防止 worker 占用内存持续增长</title>
      <description>&lt;p&gt;git 地址&lt;a href="https://github.com/kzk/unicorn-worker-killer" rel="nofollow" target="_blank" title=""&gt;https://github.com/kzk/unicorn-worker-killer&lt;/a&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Thu, 12 May 2016 17:00:41 +0800</pubDate>
      <link>https://ruby-china.org/topics/30000</link>
      <guid>https://ruby-china.org/topics/30000</guid>
    </item>
    <item>
      <title>推荐两篇文章--讲述浏览器历史的</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2016/522ddf30f009bfe6ab63695b147bd160.jpg" title="" alt=""&gt;&lt;/p&gt;
&lt;h2 id=""&gt;&lt;img src="https://l.ruby-china.com/photo/2016/b7c83066b001c417be35ee1ed21a223b.jpg" title="" alt=""&gt;&lt;/h2&gt;
&lt;p&gt;链接
&lt;a href="http://litten.github.io/2014/09/26/history-of-browser-useragent/" rel="nofollow" target="_blank" title=""&gt;http://litten.github.io/2014/09/26/history-of-browser-useragent/&lt;/a&gt;
&lt;a href="http://litten.github.io/2014/10/05/history-of-browser-useragent2/" rel="nofollow" target="_blank" title=""&gt;http://litten.github.io/2014/10/05/history-of-browser-useragent2/&lt;/a&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Tue, 03 May 2016 09:23:43 +0800</pubDate>
      <link>https://ruby-china.org/topics/29899</link>
      <guid>https://ruby-china.org/topics/29899</guid>
    </item>
    <item>
      <title>Launch a  subprocess in Ruby</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2016/e2613c61cb19ab301dda3b92b94a7cfc.png" title="" alt=""&gt;&lt;/p&gt;

&lt;hr&gt;

&lt;p&gt;&lt;a href="http://stackoverflow.com/questions/6338908/ruby-difference-between-exec-system-and-x-or-backticks/18623297#18623297" rel="nofollow" target="_blank" title=""&gt;原文地址&lt;/a&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Wed, 20 Apr 2016 09:29:26 +0800</pubDate>
      <link>https://ruby-china.org/topics/29785</link>
      <guid>https://ruby-china.org/topics/29785</guid>
    </item>
    <item>
      <title>carrierwave 使用时间戳重命名文件以及在 version 中动态指定图片尺寸</title>
      <description>&lt;h3 id="以下是在项目中做图片上传遇到的需求以及解决方案"&gt;以下是在项目中做图片上传遇到的需求以及解决方案&lt;/h3&gt;&lt;h3 id="1.  使用时间戳重新命名上传的文件"&gt;1.  使用时间戳重新命名上传的文件&lt;/h3&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def filename
   @name ||= "#{timestamp}.#{file.extension.downcase}" if original_filename.present? and super.present?
 end


 def timestamp
   var = :"@#{mounted_as}_timestamp"
   model.instance_variable_get(var) or model.instance_variable_set(var, Time.zone.now.strftime('%Y%m%d%H%M%S'))
 end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;参考
&lt;a href="https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Use-a-timestamp-in-file-names" rel="nofollow" target="_blank" title=""&gt;https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Use-a-timestamp-in-file-names&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="2.  version中动态指定图片尺寸"&gt;2.  version 中动态指定图片尺寸&lt;/h3&gt;
&lt;p&gt;原图需要根据指定的宽，计算实际生成图片时的高&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version :demo do
    process :calculate_demo =&amp;gt; 1242
  end

def calculate_demo(standard_width)
    standard_width = standard_width.to_f
    file_dimensions = ::MiniMagick::Image.open(file.file)[:dimensions]#[width, height]#使用MiniMagick获取原始图片宽度
    standard_height = (standard_width * file_dimensions[1] / file_dimensions[0]).to_i
    resize_to_fit standard_width.to_i, standard_height
  end

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;参考
1.&lt;a href="https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Get-image-dimensions" rel="nofollow" target="_blank" title=""&gt;获取图片的维度&lt;/a&gt;
1.&lt;a href="http://www.diowa.com/blog/rails/2014/03/22/using-one-carrierwave-image-uploader-with-dynamic-versions/" rel="nofollow" target="_blank" title=""&gt;http://www.diowa.com/blog/rails/2014/03/22/using-one-carrierwave-image-uploader-with-dynamic-versions/&lt;/a&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Sat, 27 Feb 2016 11:06:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/29124</link>
      <guid>https://ruby-china.org/topics/29124</guid>
    </item>
    <item>
      <title>&lt;% var do -%&gt;里面的 "-"是一种什么用法</title>
      <description>&lt;p&gt;如图，圈起来的地方是一种什么用法，好像在那里见过。
&lt;img src="https://l.ruby-china.com/photo/2016/8dd20163e87e35daaef3d070b6181354.png" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>zouyu</author>
      <pubDate>Fri, 26 Feb 2016 22:22:14 +0800</pubDate>
      <link>https://ruby-china.org/topics/29122</link>
      <guid>https://ruby-china.org/topics/29122</guid>
    </item>
  </channel>
</rss>
