<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>hicupp</title>
    <link>https://ruby-china.org/hicupp</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>在 scope 中如何对某字段的值进行处理</title>
      <description>&lt;p&gt;问题描述：
  一个常见的 scope 是这样的：&lt;/p&gt;

&lt;p&gt;scope :compare, lambda { |sth| :conditions =&amp;gt; ['content = ?', sth] }&lt;/p&gt;

&lt;p&gt;调用：&lt;/p&gt;

&lt;p&gt;model.compare(sth)&lt;/p&gt;

&lt;p&gt;我们做的是将传入的 sth 与字段 content 比较，有没有办法能在 scope 里动态地拿到 content 字段的内容做一些处理？&lt;/p&gt;

&lt;p&gt;如这种形式：&lt;/p&gt;

&lt;p&gt;scope :compare, lambda { |sth| :conditions =&amp;gt; ['t[:content].do_some_solve = ?', sth] }&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Wed, 09 Oct 2013 14:07:11 +0800</pubDate>
      <link>https://ruby-china.org/topics/14613</link>
      <guid>https://ruby-china.org/topics/14613</guid>
    </item>
    <item>
      <title>关于 XML 转 Hash</title>
      <description>&lt;p&gt;碰到一个问题：从一个网站获得了 rss 的 xml 的字符串，现在想把其中的内容提取出来，决定把它转化为 hash 再提取。google 了一下，使用&lt;/p&gt;

&lt;p&gt;&lt;code&gt;data = Hash.from_xml(xml)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;可是报了错：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#&amp;lt;REXML::ParseException: Declarations can only occur in the doctype declaration.
Line: 1
Position: 271610
Last 80 unconsumed characters:
&amp;lt;![CDATA[&amp;lt;div style="text-align: center; line-height: 200%" align="center"&amp;gt;&amp;amp;nbsp;&amp;gt;
/Users/kgtong/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:355:in `pull_event'
/Users/kgtong/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:183:in `pull'
/Users/kgtong/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:22:in `parse'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;查了半天也没找到解决方法，希望大家给一些思路哈。&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Fri, 27 Sep 2013 11:30:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/14428</link>
      <guid>https://ruby-china.org/topics/14428</guid>
    </item>
    <item>
      <title>[已解决] 如何动态地在 hash 里存 hash</title>
      <description>&lt;p&gt;如题，在存储数据时遇到这样的问题：
想实现这样的存储方式：&lt;/p&gt;

&lt;p&gt;data = {
                 'info' =&amp;gt; [
                             {'name' =&amp;gt; 'xx', id =&amp;gt; 'xxxx', ...},
                             {'name' =&amp;gt; 'xx', id =&amp;gt; 'xxxx', ...},
                             {'name' =&amp;gt; 'xx', id =&amp;gt; 'xxxx', ...}
                           ]
              }
现在申明了一个&lt;/p&gt;

&lt;p&gt;data ＝ {}
    data['info'] = {}
通过迭代新建若干条数据 a：&lt;/p&gt;

&lt;p&gt;a = {'name' =&amp;gt; 'xx', id =&amp;gt; 'xxx'}
怎么把 a 按上述的方式插入到 data 中，多谢哈～&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Mon, 09 Sep 2013 13:13:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/13978</link>
      <guid>https://ruby-china.org/topics/13978</guid>
    </item>
    <item>
      <title>关于 before_filter</title>
      <description>&lt;p&gt;各位大大们:
  发送一个 remote 为 true 的 post 请求给某个 controller，这个 controller 先用 before_filter 对请求进行验证，在 before_filter 里我这么写：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;before_filter&lt;/span&gt; &lt;span class="ss"&gt;:check&lt;/span&gt;
&lt;span class="kp"&gt;protected&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xhr?&lt;/span&gt;
    &lt;span class="n"&gt;dosomething&lt;/span&gt;
    &lt;span class="c1"&gt;#如果不满足条件&lt;/span&gt;
    &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;root_url&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;发现请求设置了 remote 为 true，这儿就跳转不了，一旦去掉 remote 为 true 就能正常跳转。怎么才能使 remote 为 true 的请求在进行 before_filter 时可以顺利的&lt;code&gt;redirect_to root_url&lt;/code&gt;&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Sun, 04 Aug 2013 17:56:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/13043</link>
      <guid>https://ruby-china.org/topics/13043</guid>
    </item>
    <item>
      <title>国内的 Ruby 招聘</title>
      <description>&lt;p&gt;小白问题但是比较现实。。明年就毕业了，想做这方面的工作。除了在论坛里看到的这些招聘，国内招聘 ruby 包括 rails 程序员的公司还有哪些啊，有没有像知乎、豆瓣、点点这样的比较新的公司？&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Mon, 22 Jul 2013 21:07:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/12683</link>
      <guid>https://ruby-china.org/topics/12683</guid>
    </item>
    <item>
      <title>关于遍历每条记录的字段的值</title>
      <description>&lt;p&gt;小白问题：如何写迭代语句才能遍历每条记录的每个字段的值？求教～&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Tue, 09 Jul 2013 19:30:01 +0800</pubDate>
      <link>https://ruby-china.org/topics/12379</link>
      <guid>https://ruby-china.org/topics/12379</guid>
    </item>
    <item>
      <title>Rake assets:precompile 引起的错误</title>
      <description>&lt;p&gt;大家好：
  今天在使用 Nginx + Passenger 部署项目。遇到了一个问题，寻求各位高手的帮助。当我执行：
    &lt;code&gt;rake assets:precompile&lt;/code&gt;
    报错：&lt;/p&gt;

&lt;p&gt;Invalid CSS after "*": expected "{", was "html .fixed"
    "html" may only be used at the beginning of a compound selector.
     (in /home/hicupp/rail/testapp/app/assets/stylesheets/application.css)(sass):37
另外我在 production.rb 中已设置：&lt;/p&gt;

&lt;p&gt;&lt;code&gt;config.assets.compile = true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;这是什么原因啊？&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Mon, 08 Jul 2013 11:22:22 +0800</pubDate>
      <link>https://ruby-china.org/topics/12337</link>
      <guid>https://ruby-china.org/topics/12337</guid>
    </item>
    <item>
      <title>关于 HTML5 的 audio 标签在 Rails 中的使用</title>
      <description>&lt;p&gt;大家好：
问题描述：这两天在倒腾 auto，遇到一个问题，向大家请教下。我随机新建一个 html 文件，然后测试：
&lt;code&gt;&amp;lt;audio src='/home/hicupp/rails/test_1/hello.ogg' controls="controls"&amp;gt;
Your browser does not support the audio tag.
&amp;lt;/audio&amp;gt;&lt;/code&gt;
结果音频文件正常播放。
但是到了 rails 程序里，还是这个语句，就播放不了了。于是果断 F12 调试了下，试图打开那个音频文件但是结果却是：
&lt;code&gt;No route matches [GET] "/home/hicupp/rails/test_1/hello.ogg"&lt;/code&gt;。这是什么原因啊？&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Tue, 02 Jul 2013 21:20:03 +0800</pubDate>
      <link>https://ruby-china.org/topics/12197</link>
      <guid>https://ruby-china.org/topics/12197</guid>
    </item>
    <item>
      <title>关于多对多条件查询</title>
      <description>&lt;p&gt;大家好：
  问题描述：有两个 model，Student 和 Teacher，它们是多对多的关系。中间的关系模型为 Student_Teahcer. 在 student_teachers 表里有 4 个字段：id，student_id, teacher_id 以及 mark。mark 字段有两种状态：0 和 1.
当我想调用
    &lt;code&gt;@students = teacher1.students&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;时，怎么才能实现调用结果里 students 和 teacher1 在 student_teacher 对应的 mark 字段为 1.能通过申明 has_many 关系时用 where 或者 condition 么？还是其他方法？&lt;/p&gt;</description>
      <author>hicupp</author>
      <pubDate>Mon, 01 Jul 2013 10:22:11 +0800</pubDate>
      <link>https://ruby-china.org/topics/12132</link>
      <guid>https://ruby-china.org/topics/12132</guid>
    </item>
  </channel>
</rss>
