<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>machixian (马齿苋)</title>
    <link>https://ruby-china.org/machixian</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>使用 jQuery File Upload 的同学请绕开 Rails 3.2.13</title>
      <description>&lt;p&gt;这两天尝试学习用 jQuery file upload+Carrierwave 做文件上传功能，使用的是 simple_form，结果碰到了一个很奇怪的问题，在学习 Railscasts 381 jQuery file upload 的时候里面明确的说了当 input field 的 multiple 设置为 true 的时候要将其 name 由默认的"image[name][]"成"image[name]"，即把后面的中括号去掉，因为 jQuery file upload 会默认将文件一个个上传而不是一次提交所有的文件，要不改的话 Carrierwave 会报错的，所以就很自然的用 simple_form 这么做了&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= f.input :name, :label =&amp;gt; "Upload image", :input_html =&amp;gt; { :multiple =&amp;gt; true, :name =&amp;gt; "image[name]" }, as: :file %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但是出来的结果却是&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="controls"&amp;gt;
  &amp;lt;input type="file" name="image[name][]" multiple="multiple" id="image_name" class="file optional"&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;name 属性没有变化，因为之前看 Railscast 里面用的是 f.file_field 来自定义的，所以就想当然的认为问题出在 simple_form 上面，然后就是各种 Google，结果当然是一无所获。最后终于则决定放弃 simple_form，直接使用 rails 带的 from builder 吧，然后才发现问题依旧，使用下面的代码依旧不能自定义 name 属性&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= f.file_field :path, multiple: true, name: "image[name]" %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;后来使用"f.file_field override :name "这个关键字终于搜到了 github 上面的这个&lt;a href="https://github.com/rails/rails/issues/9830" rel="nofollow" target="_blank" title=""&gt;issue&lt;/a&gt;，敢情问题是出在 Rails 身上。&lt;/p&gt;

&lt;p&gt;最后将 Rails 降到 3.2.12 之后问题就解决了。&lt;/p&gt;</description>
      <author>machixian</author>
      <pubDate>Mon, 27 May 2013 09:49:10 +0800</pubDate>
      <link>https://ruby-china.org/topics/11252</link>
      <guid>https://ruby-china.org/topics/11252</guid>
    </item>
    <item>
      <title>有谁在 Rails 项目中使用过 bootswatch 么？</title>
      <description>&lt;p&gt;我做了几次不同的尝试都没有成功。&lt;/p&gt;

&lt;p&gt;第一种是使用&lt;a href="https://github.com/seyhunak/twitter-bootstrap-rails" rel="nofollow" target="_blank" title=""&gt;twitter-bootstrap-rails&lt;/a&gt;，然后在 bootswatch.com 下载某个 theme 的 variables.less 和 bootswatch.less 文件加入到 stylesheets 目录中，再在&lt;code&gt;bootstrap_and_overrides.css.less&lt;/code&gt;最开始加入&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "variables";
@import "bootswatch";
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;但是最后会报错：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box-shadow is undefined
  (in /Projects/my/app/assets/stylesheets/bootswatch.less)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;另外一个尝试是使用&lt;a href="https://github.com/scottvrosenthal/twitter-bootswatch-rails" rel="nofollow" target="_blank" title=""&gt;twitter-bootswatch-rails&lt;/a&gt;，加入 gems 之后安装的步骤是&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g bootswatch:install simplex
rails g bootswatch:import simplex
rails g bootswatch:layout application
rails g bootswatch:themed items
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样做完之后访问 localhost:3000/items 还是报跟上面一样的错误。&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box-shadow is undefined
  (in /Projects/my/app/assets/stylesheets/bootswatch.less)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我的目的很简单，就是使用 bootswatch 的其中一个 theme，不需要做到能切换的，在整个项目的页面都默认使用这个 theme 就行。&lt;/p&gt;

&lt;p&gt;有谁对使用 bootswatch 比较熟悉的麻烦指点一下。&lt;/p&gt;</description>
      <author>machixian</author>
      <pubDate>Thu, 25 Apr 2013 18:37:00 +0800</pubDate>
      <link>https://ruby-china.org/topics/10504</link>
      <guid>https://ruby-china.org/topics/10504</guid>
    </item>
  </channel>
</rss>
