<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>tonytonyjan (大兜)</title>
    <link>https://ruby-china.org/tonytonyjan</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>rails database.yml 与 config.yml 的配置方法</title>
      <description>&lt;p&gt;跟这问题很像： &lt;a href="http://ruby-china.org/topics/18849" rel="nofollow" target="_blank"&gt;http://ruby-china.org/topics/18849&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;就我所知目前主流的方法就两个：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;将设定档加到 &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;利用环境变数（environment variable）&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;老实说一直以来我都是用第一个方法，也用的很习惯，但实在想不出第二个方法应该怎么用比较符合正确的工作流？&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;问题一&lt;/strong&gt;
怎么管理本地端众多的 rails app？因为每个 app 所需要的环境变数都不尽相同，这样设来设去的会很麻烦。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;问题二&lt;/strong&gt;
有个东西叫 dotenv，把变数都放在 &lt;code&gt;.env&lt;/code&gt; 档里面，可是这种方法还不是要把 &lt;code&gt;.env&lt;/code&gt; 加进 &lt;code&gt;.gitignore&lt;/code&gt; 吗？跟第一个方法相较起来岂不是脱裤子放屁？&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;问题三&lt;/strong&gt;
部署端有时候会由一个帐号执行多个 app（例如 server 上所有的 app 都是由一个叫 deploy 的 user 执行的），这些 app 彼此间的环境变数又该怎么控管？&lt;/p&gt;

&lt;p&gt;希望可以向各位前辈们取经，十分感谢！&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Tue, 06 May 2014 01:55:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/19034</link>
      <guid>https://ruby-china.org/topics/19034</guid>
    </item>
    <item>
      <title>How to avoid conflicting when naming model attributes? </title>
      <description>&lt;p&gt;想跟各位前辈请教一下，请问有什么好方法可以避免在 generate model 时，attribute name 不会与 &lt;code&gt;ActiveRecord::Base&lt;/code&gt; instance 既有的 method name 冲突？&lt;/p&gt;

&lt;p&gt;例如，我们的 attribute name 不会命名成 &lt;code&gt;class&lt;/code&gt; 或 &lt;code&gt;toggle&lt;/code&gt;。&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Sun, 05 May 2013 11:55:51 +0800</pubDate>
      <link>https://ruby-china.org/topics/10717</link>
      <guid>https://ruby-china.org/topics/10717</guid>
    </item>
    <item>
      <title>gem about ranking or hot algorithm</title>
      <description>&lt;p&gt;想请教一下现今有没有什么 ranking (or hot) algorithm 相关的 gem 是用 strategy pattern 下去做的，像 omniauth 那样，最近在盘算开个这样的 project，但怕撞到别人的。&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Wed, 19 Dec 2012 00:04:28 +0800</pubDate>
      <link>https://ruby-china.org/topics/7676</link>
      <guid>https://ruby-china.org/topics/7676</guid>
    </item>
    <item>
      <title>管理的 JS assets 的方法</title>
      <description>&lt;h2 id="Rails Guide Style"&gt;Rails Guide Style&lt;/h2&gt;
&lt;p&gt;在 &lt;a href="http://edgeguides.rubyonrails.org/asset_pipeline.html#how-to-use-the-asset-pipeline" rel="nofollow" target="_blank" title=""&gt;Rails Guide 上面&lt;/a&gt;有这样的写法：&lt;/p&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;javascript_include_tag&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;:controller&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
or 
&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;stylesheet_link_tag&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;:controller&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但是这样写的话，在 production 时一定会报错，所以要在 &lt;code&gt;config.assets.precompile&lt;/code&gt; 加上不少东西，类似：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;precompile&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="sr"&gt;/\.(css|js)\z/&lt;/span&gt;
      &lt;span class="n"&gt;full_path&lt;/span&gt; &lt;span class="o"&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;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_path&lt;/span&gt;
      &lt;span class="n"&gt;app_assets_path&lt;/span&gt; &lt;span class="o"&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;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'assets'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_path&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;full_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;starts_with?&lt;/span&gt; &lt;span class="n"&gt;app_assets_path&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"including asset: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;full_path&lt;/span&gt;
        &lt;span class="kp"&gt;true&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"excluding asset: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;full_path&lt;/span&gt;
        &lt;span class="kp"&gt;false&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="kp"&gt;false&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;然而这在 Rails Guide 上面并没有提醒我们要做这件事情&lt;/strong&gt;（所以想贡献一下这个提示到 docrails 这个 repo 上）&lt;/p&gt;
&lt;h2 id="Garber Irish Style"&gt;Garber Irish Style&lt;/h2&gt;
&lt;p&gt;然而有另外一种方案：&lt;a href="http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution" rel="nofollow" target="_blank"&gt;http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;使用起来的话，以 &lt;code&gt;posts.js.coffee&lt;/code&gt; 为例子：&lt;/p&gt;
&lt;pre class="highlight coffeescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SITENAME&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;# blablabla&lt;/span&gt;
  &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;# blablabla&lt;/span&gt;
  &lt;span class="na"&gt;new&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;# blablabla&lt;/span&gt;
  &lt;span class="na"&gt;edit&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;# blablabla&lt;/span&gt;
  &lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;# blablabla&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我觉得很有条理，而且比上述的 Rails Guide style 简单很多，如果要共用重复的代码也可以这么做：&lt;/p&gt;
&lt;pre class="highlight coffeescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SITENAME&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="na"&gt;new&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="na"&gt;edit&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;do_something&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;#blablabla&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;因为管理方便，所以最近的专案都开始使用这个方法了。&lt;/p&gt;

&lt;hr&gt;

&lt;p&gt;来此除了推广 Garber Irish 的方法之外，也想向各位取经：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;h2 id="不知道大家是怎么管理自己的 javascript assets 的？"&gt;不知道大家是怎么管理自己的 javascript assets 的？&lt;/h2&gt;&lt;/li&gt;
&lt;li&gt;&lt;h2 id="大家会选择上述哪一个方法？"&gt;大家会选择上述哪一个方法？&lt;/h2&gt;&lt;/li&gt;
&lt;/ol&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Wed, 05 Dec 2012 01:39:05 +0800</pubDate>
      <link>https://ruby-china.org/topics/7315</link>
      <guid>https://ruby-china.org/topics/7315</guid>
    </item>
    <item>
      <title>让 user 关联 record</title>
      <description>&lt;p&gt;在 controller 里面各位会选择这样写：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def new
  @post = current_user.posts.build
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;然后在 form 里面加个 hidden input&lt;/p&gt;

&lt;p&gt;或者&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create
  @post = current_user.posts.build(params[:post])
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;只是好奇：)&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Mon, 26 Nov 2012 18:01:19 +0800</pubDate>
      <link>https://ruby-china.org/topics/7107</link>
      <guid>https://ruby-china.org/topics/7107</guid>
    </item>
    <item>
      <title>TJMarkdownPaste - Markdown with code highlight and Tex mathematical syntax</title>
      <description>&lt;p&gt;网址在此：&lt;a href="http://tj-markdown-paste.herokuapp.com/" rel="nofollow" target="_blank"&gt;http://tj-markdown-paste.herokuapp.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Markdown 这么好用，要是可以程式码自动上色和使用 Tex 数学符号该有多好呢？&lt;/p&gt;

&lt;p&gt;昨晚因为这样一个发想，立刻就做出雏型了，前后花费一共 14 个小时，不禁要赞叹一下用 Rails 的神速。&lt;/p&gt;
&lt;h2 id="后计"&gt;后计&lt;/h2&gt;
&lt;p&gt;这是昨晚 11:30 突然有的想法，然后花了 14 个小时兜出来的东西，同时破了上次坐在椅子上 11 小时的纪录……Orz（这似乎没什么好说嘴……（艸））&lt;/p&gt;

&lt;p&gt;也许未来还有许多新的功能（还没想到），先放出来给各位玩玩看，如果觉得还要新增什么东西也可以告诉我 XD&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Thu, 22 Nov 2012 03:38:17 +0800</pubDate>
      <link>https://ruby-china.org/topics/6988</link>
      <guid>https://ruby-china.org/topics/6988</guid>
    </item>
    <item>
      <title>如何在 Google SketchUp 使用 rubygems？</title>
      <description>&lt;p&gt;&lt;a href="http://stackoverflow.com/questions/12480694/require-rubygems-in-sketchup" rel="nofollow" target="_blank" title=""&gt;完整問題在此&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;環境：
Windows 7
Ruby 1.8.6
SketchUp 8.0.14346&lt;/p&gt;

&lt;p&gt;狀況：&lt;/p&gt;

&lt;p&gt;我想要寫一個 plugin 去連結 MongoDB，當然首選的 gem 就是 mongo，遇到的第一個問題就是如何在 SketchUp 裡面使用 rubygems。&lt;/p&gt;

&lt;p&gt;一個晚上搞不定，只好來這裡求神拜佛了 Orz&lt;/p&gt;

&lt;p&gt;另外也有一個人遇到和我&lt;a href="http://www.smustard.com/forum/viewtopic.php?f=6&amp;amp;t=96" rel="nofollow" target="_blank" title=""&gt;一樣的問題&lt;/a&gt;，提供參考，只是他們也還沒找到答案 QQ&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Wed, 19 Sep 2012 00:14:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/5621</link>
      <guid>https://ruby-china.org/topics/5621</guid>
    </item>
    <item>
      <title>各位怎么管理 css 和 javascript assets</title>
      <description>&lt;p&gt;就依照 RESTful 的设计，例如一个 Post resource 就有 new、edit、show 和 index 四个 page，如果我对于这四个页面都有他们各自的 css 和 script，我现在是都写在 &lt;code&gt;app/assets/javascripts/posts.js.coffee&lt;/code&gt; 和 &lt;code&gt;app/assets/stylesheets/posts.css.scss&lt;/code&gt; 里面。&lt;/p&gt;

&lt;p&gt;但这样进入各个 page 常会载入用不到的东西（例如进入 show，会载入 &lt;code&gt;posts.js.coffee&lt;/code&gt; 和 &lt;code&gt;posts.css.scss&lt;/code&gt; 但只用得到里面的 1/4 的程式码和 style）。&lt;/p&gt;

&lt;p&gt;但若把 javascript 和 css 又各分成 4 个，这样会变成 8 个档案。在进行 assets precompile 之前，我要在 &lt;code&gt;config/environments/production.rb&lt;/code&gt; 先定义额外的 assets：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.assets.precompile += %w(posts_new.css posts_edit.css posts_show.css posts_index.css)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样会变得很冗长，所以想来此请教前辈们该如何管理这些档案比较恰当？&lt;/p&gt;

&lt;p&gt;把全网站的 javascript 和 css 档案 precompile 成 1 个档案是好方法吗？&lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Mon, 03 Sep 2012 00:13:46 +0800</pubDate>
      <link>https://ruby-china.org/topics/5324</link>
      <guid>https://ruby-china.org/topics/5324</guid>
    </item>
    <item>
      <title>酷站里面的连结要怎么删掉？</title>
      <description>&lt;p&gt;我记得 Twitter 已经抛弃 Ruby 投向 Java 的怀抱，所以应该可以拿掉了吧？  &lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Sat, 05 May 2012 02:59:17 +0800</pubDate>
      <link>https://ruby-china.org/topics/3083</link>
      <guid>https://ruby-china.org/topics/3083</guid>
    </item>
    <item>
      <title>自制外挂：将 Octopress Page 依照 heading 自动索引</title>
      <description>&lt;p&gt;如果看不懂标题是什么意思，其实就是类似在 wiki 页面上方常出现的巢状索引栏，让你可以快速跳跃到某个标题。&lt;/p&gt;

&lt;p&gt;我因为想再 Octopress 上写文件，但苦于设定 id，所以自己动手做了一个 plugin，会依照文章的 heading 产生相对应的巢状索引。&lt;/p&gt;

&lt;p&gt;有兴趣的人可以先看看 Demo：&lt;a href="http://tonytonyjan.github.com/blog/octopress-indexer/" rel="nofollow" target="_blank"&gt;http://tonytonyjan.github.com/blog/octopress-indexer/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;我也有为此发一篇开发杂记：&lt;a href="http://tonytonyjan.github.com/2012/05/01/indexer-for-octopress/" rel="nofollow" target="_blank"&gt;http://tonytonyjan.github.com/2012/05/01/indexer-for-octopress/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;灵感来自 Rails Guide &lt;a href="http://guides.rubyonrails.org/getting_started.html" rel="nofollow" target="_blank"&gt;http://guides.rubyonrails.org/getting_started.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;题外话：第一次光顾 Ruby China，总觉得 Ruby Taiwan 有点冷清啊 QAQ  &lt;/p&gt;</description>
      <author>tonytonyjan</author>
      <pubDate>Sat, 05 May 2012 02:38:57 +0800</pubDate>
      <link>https://ruby-china.org/topics/3082</link>
      <guid>https://ruby-china.org/topics/3082</guid>
    </item>
  </channel>
</rss>
