<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>サイキョウライン &#187; Rails</title>
	<atom:link href="http://saikyoline.jp/weblog/category/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://saikyoline.jp/weblog</link>
	<description>コンピュータに関係あることとか、ないこととか。</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:17:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>fixtureにcsvが使えなくなる。</title>
		<link>http://saikyoline.jp/weblog/2012/01/20/003957.html</link>
		<comments>http://saikyoline.jp/weblog/2012/01/20/003957.html#comments</comments>
		<pubDate>Thu, 19 Jan 2012 15:39:57 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1386</guid>
		<description><![CDATA[DEPRECATION WARNING: read_csv_fixture_files is deprecated and will be removed from Rails 3.2. なんてことを言われてるんですが、 [...]]]></description>
			<content:encoded><![CDATA[<pre class="code"><code>DEPRECATION WARNING: read_csv_fixture_files is deprecated and will be removed from Rails 3.2.</code></pre>
<p>なんてことを言われてるんですが、なんでcsv受け付けなくなっちゃうんでしょ？</p>
<p><em>activerecord-3.1.3/lib/active_record/fixtures.rb</em></p>
<pre class="code"><code>684       def read_csv_fixture_files
685         reader = CSV.parse(erb_render(IO.read(csv_file_path)))
686         header = reader.shift
687         i = 0
688         reader.each do |row|
689           data = {}
690           row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
691           fixtures[&quot;#{@class_name.to_s.underscore}_#{i+=1}&quot;] = ActiveRecord::Fixture.new(data, model_class)
692         end
693       end
694       deprecate :read_csv_fixture_files</code></pre>
<p>csv便利なのになぁ。</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2012/01/20/003957.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails3.1でPsych::SyntaxErrorの時に見るところ。</title>
		<link>http://saikyoline.jp/weblog/2011/11/04/024956.html</link>
		<comments>http://saikyoline.jp/weblog/2011/11/04/024956.html#comments</comments>
		<pubDate>Thu, 03 Nov 2011 17:49:56 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1340</guid>
		<description><![CDATA[Commit dc94d813e2d158c5a284212c5d8146c677dbb877 to rails/rails &#8211; GitHub fixing invalid yaml [#4418 state [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="https://github.com/rails/rails/commit/dc94d81" title="Commit dc94d813e2d158c5a284212c5d8146c677dbb877 to rails/rails - GitHub"><p><a href="https://github.com/rails/rails/commit/dc94d81">Commit dc94d813e2d158c5a284212c5d8146c677dbb877 to rails/rails &#8211; GitHub</a></p>
<p>fixing invalid yaml [#4418 state:resolved] </p></blockquote>
<p>ここ、あなたのconfig/locales/active_support_ja.ymlではどうなってますか？</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2011/11/04/024956.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails3のチートシート。</title>
		<link>http://saikyoline.jp/weblog/2011/01/04/004517.html</link>
		<comments>http://saikyoline.jp/weblog/2011/01/04/004517.html#comments</comments>
		<pubDate>Mon, 03 Jan 2011 15:45:17 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1129</guid>
		<description><![CDATA[Rails 3 Cheat Sheets « Envy Labs Today I’m happy to finally release the Envy Labs Rails 3 Cheat Sheets. ルーティング [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://blog.envylabs.com/2010/12/rails-3-cheat-sheets/" title="Rails 3 Cheat Sheets « Envy Labs"><p><a href="http://blog.envylabs.com/2010/12/rails-3-cheat-sheets/">Rails 3 Cheat Sheets « Envy Labs</a></p>
<p>Today I’m happy to finally release the Envy Labs Rails 3 Cheat Sheets.</p></blockquote>
<p>ルーティングだとかbundleだとか、書いてて「えーと、なんだっけ？」になるところがまとまってます。いいね！</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2011/01/04/004517.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>default_scopeを個別に外す。</title>
		<link>http://saikyoline.jp/weblog/2010/11/18/010050.html</link>
		<comments>http://saikyoline.jp/weblog/2010/11/18/010050.html#comments</comments>
		<pubDate>Wed, 17 Nov 2010 16:00:50 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1084</guid>
		<description><![CDATA[default_scopeを全部外すにはunscopedだったのですが、特定の条件だけ外すにはどうしたらよいのか調べていたら、こちらにたどり着きました。 default_scopeのorderをキャンセルする &#821 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://saikyoline.jp/weblog/2010/11/14/002339.html">default_scopeを全部外すにはunscopedだった</a>のですが、特定の条件だけ外すにはどうしたらよいのか調べていたら、こちらにたどり着きました。</p>
<blockquote cite="http://www.sonorilo.net/2010/11/08/2770" title="default_scopeのorderをキャンセルする - とある技術屋の戯言"><p><a href="http://www.sonorilo.net/2010/11/08/2770">default_scopeのorderをキャンセルする &#8211; とある技術屋の戯言</a></p>
<p>Model.reorder(&#8216;id DESC&#8217;)</p></blockquote>
<p>おーなるほどと思いつつ、他にもあるのかとドキュメントを見に行ったら・・・（[ show source ]をクリック）</p>
<blockquote cite="http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-reorder" title="Module: ActiveRecord::QueryMethods"><p><a href="http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-reorder">Module: ActiveRecord::QueryMethods</a></p>
<p># File activerecord/lib/active_record/relation/query_methods.rb, line 56<br /> 56: def reorder(*args)<br /> 57: ActiveSupport::Deprecation.warn &quot;<strong>reorder is deprecated. Please use except(:order).order(&#8230;) instead</strong>&quot;, caller<br /> 58: relation = clone </p></blockquote>
<p>ん？</p>
<pre class="code"><code>class Article &lt; ActiveRecord::Base
  default_scope where(:disclosed =&gt; true).order('disclosed_at DESC')
end

Article.all #=&gt; SELECT &quot;articles&quot;.* FROM &quot;articles&quot; WHERE (&quot;articles&quot;.&quot;disclosed&quot; = 't') ORDER BY disclosed_at DESC
Article.except(:where).all #=&gt; SELECT &quot;articles&quot;.* FROM &quot;articles&quot; ORDER BY disclosed_at DESC
Article.except(:order).all #=&gt; SELECT &quot;articles&quot;.* FROM &quot;articles&quot; WHERE (&quot;articles&quot;.&quot;disclosed&quot; = 't')</code></pre>
<p>ほほー。</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/11/18/010050.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>default_scopeはunscopedで外す。</title>
		<link>http://saikyoline.jp/weblog/2010/11/14/002339.html</link>
		<comments>http://saikyoline.jp/weblog/2010/11/14/002339.html#comments</comments>
		<pubDate>Sat, 13 Nov 2010 15:23:39 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1080</guid>
		<description><![CDATA[with_exclusive_scope (ActiveRecord::Base) &#8211; APIdock In Rails3 use &#34;unscoped&#34; instead The with_ [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://apidock.com/rails/ActiveRecord/Base/with_exclusive_scope/class#964-In-Rails3-use-unscoped-instead" title="with_exclusive_scope (ActiveRecord::Base) - APIdock"><p><a href="http://apidock.com/rails/ActiveRecord/Base/with_exclusive_scope/class#964-In-Rails3-use-unscoped-instead">with_exclusive_scope (ActiveRecord::Base) &#8211; APIdock</a></p>
<p>In Rails3 use &quot;unscoped&quot; instead</p>
<p>The with_exclusive_scope examples no longer work in Rails3 because with_exclusive_scope is now a protected method which can and should not be used in a controller. Use the new unscoped method instead:</p></blockquote>
<p>ほー。</p>
<pre class="code"><code>class Post &lt; ActiveRecord::Base
  default_scope :published =&gt; true
end

Post.all #=&gt; SELECT * FROM posts WHERE published = true

Post.unscoped.all #=&gt; SELECT * FROM posts</code></pre>
<p>ほほー。</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/11/14/002339.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>rails3とdmでsqliteのdbファイルができない。</title>
		<link>http://saikyoline.jp/weblog/2010/10/07/142758.html</link>
		<comments>http://saikyoline.jp/weblog/2010/10/07/142758.html#comments</comments>
		<pubDate>Thu, 07 Oct 2010 05:27:58 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1055</guid>
		<description><![CDATA[「Rails3でO/RマッパをDataMapperにしてsqliteを選択したときにdbファイルが作られない。」という舌をかみそうな現象に遭遇したのでご紹介。 結論から言うと、こちらのようにdatabaseではなくpat [...]]]></description>
			<content:encoded><![CDATA[<p>「Rails3でO/RマッパをDataMapperにしてsqliteを選択したときにdbファイルが作られない。」という舌をかみそうな現象に遭遇したのでご紹介。<br />
結論から言うと、こちらのようにdatabaseではなくpathで書いてあげれば解決します。</p>
<blockquote cite="http://www.ruby-forum.com/topic/218006" title="Rails 3 DataMapper dm-rails sqlite3 issue - Ruby Forum"><p><a href="http://www.ruby-forum.com/topic/218006">Rails 3 DataMapper dm-rails sqlite3 issue &#8211; Ruby Forum</a></p>
<pre class="code"><code>change &quot;database&quot; to &quot;path&quot;
   database: testing_dm3_development.db
to
    path: ./db/testing_dm3_development.db</code></pre>
</blockquote>
<p>databaseのままだとファイルではなくメモリにデータが作られてしまうために、セッションが切れると飛んでしまうのが原因のようです。</p>
<p>・・・で、このままでは気持ち悪いのでどうしてこうなるかを追ってみました。</p>
<p><span id="more-1055"></span></p>
<p>まず、現象はこんな感じ。(論点ではない出力は省略)</p>
<pre class="code"><code>% ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
% rails -v
Rails 3.0.0
% rails new foo -O -m http://datamapper.org/templates/rails.rb
% cd foo
# つぎのdb:setupで怒られるので、ここでGemfileにactiveresourceを追加する。(これも問題？)
% bundle install
% rake db:setup
(in /home/yoshuki/trials/foo)
[datamapper] Created database 'foo_development.db'
[datamapper] Created database 'foo_test.db'
[datamapper] Finished auto_migrate! for :default repository 'foo_development.db'
% ls db
seeds.rb            # dbファイルがない
% rails g scaffold Post title:string body:text
% rake db:autoupgrade
(in /home/yoshuki/trials/foo)
[datamapper] Finished auto_upgrade! for :default repository 'foo_development.db'
% ls db
seeds.rb            # まだdbファイルがない</code></pre>
<p>この状態でサーバ立ち上げてアクセスしてもテーブルがないと怒られてしまいます。<br />
またdatabase.ymlはリスト1のようになっています。(コメントは省略)</p>
<p>・リスト1(<em>config/database.yml</em>)</p>
<pre class="code"><code>defaults: &amp;defaults
  adapter: sqlite

development:
  database: foo_development.db
  &lt;&lt;: *defaults
test:
  database: foo_test.db
  &lt;&lt;: *defaults
production:
  database: foo_production.db
  &lt;&lt;: *defaults</code></pre>
<p>そこでソースを漁ったところ、これらを実際に使っているのはリスト2でした。</p>
<p>・リスト2(<em><a href="http://github.com/datamapper/dm-do-adapter/blob/v1.0.2/lib/dm-do-adapter/adapter.rb">dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb</a></em>)</p>
<pre class="code"><code>215             DataObjects::URI.new(
216               @options[:adapter],
217               @options[:user] || @options[:username],
218               @options[:password],
219               @options[:host],
220               port,
221               @options[:path] || @options[:database],
222               query,
223               @options[:fragment]
224             ).freeze</code></pre>
<p>221行目でpathがなければdatabaseを使うようになっています。いまはリスト1のようにpathがなくdatabaseのみがある状態なので、これで問題ないように見えます。<br />
そして、つぎにこの@optionsを辿っていくと、リスト3に着きました。</p>
<p>・リスト3(<em><a href="http://github.com/datamapper/dm-sqlite-adapter/blob/v1.0.2/lib/dm-sqlite-adapter/adapter.rb">dm-sqlite-adapter-1.0.2/lib/dm-sqlite-adapter/adapter.rb</a></em>)</p>
<pre class="code"><code> 19       def normalize_options(options)
 20         # TODO Once do_sqlite3 accepts both a Pathname or a String,
 21         # normalizing database and path won't be necessary anymore
 22         db   = (options[:database] || options.delete('database')).to_s
 23         path = (options[:path    ] || options.delete('path')).to_s
 24
 25         options.update(:adapter =&gt; 'sqlite3', :database =&gt; db, :path =&gt; path)
 26       end</code></pre>
<p>22行目と23行目でキーをシンボルに統一しているようです。dbにはリスト1の設定値がそのまま入るのですがpathは設定していないので・・・はい、ここが原因でした。キーに:pathも&#8217;path&#8217;もなかった場合には</p>
<pre class="code"><code>path = (nil).to_s #=&gt; &quot;&quot;</code></pre>
<p>となってしまいリスト2の221行目でpathがtrueになるため、結果としてdatabaseが無視されます。そしてtrueになったpathも空っぽなので、ファイルが作られないのでした。ここでpathが&quot;&quot;ならnilに入れ替えておけばちゃんと作られるようになります。<br />
ただ、いまの<a href="http://datamapper.org/templates/rails/database.yml.rb">DataMapperのテンプレート</a>だとRAILS_ROOT直下にファイルが作られてしまうので、<a href="http://github.com/rails/rails/blob/v3.0.0/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml">デフォルトのテンプレート</a>のようにディレクトリを付けておきましょう。</p>
<pre class="code"><code>  database: foo_development.db
    ↓
  database: db/foo_development.db</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/10/07/142758.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RVMの環境をプロジェクトごとに切り替える。</title>
		<link>http://saikyoline.jp/weblog/2010/10/02/230316.html</link>
		<comments>http://saikyoline.jp/weblog/2010/10/02/230316.html#comments</comments>
		<pubDate>Sat, 02 Oct 2010 14:03:16 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1045</guid>
		<description><![CDATA[RVM: Ruby Version Manager &#8211; rvmrc The project rvmrc files are intended to be used to setup your project&#038; [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://rvm.beginrescueend.com/workflow/rvmrc/#project" title="RVM: Ruby Version Manager - rvmrc"><p><a href="http://rvm.beginrescueend.com/workflow/rvmrc/#project">RVM: Ruby Version Manager &#8211; rvmrc</a></p>
<p>The project rvmrc files are intended to be used to setup your project&#8217;s ruby environment when you switch to the project root directory.</p></blockquote>
<p>以下のようにしておくと、それ以下のディレクトリに降りた時に自動で環境が切り替わるようになります。これは便利だなー。</p>
<pre class="code"><code>echo &quot;rvm foo@bar&quot; &gt; ~/projects/baz/.rvmrc</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/10/02/230316.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nativeなgemをBundlerで。</title>
		<link>http://saikyoline.jp/weblog/2010/08/21/182150.html</link>
		<comments>http://saikyoline.jp/weblog/2010/08/21/182150.html#comments</comments>
		<pubDate>Sat, 21 Aug 2010 09:21:50 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=1017</guid>
		<description><![CDATA[Bundler: The best way to manage Ruby applications Install all gems into vendor/bundle, even gems that are alre [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://gembundler.com/bundle_install.html" title="Bundler: The best way to manage Ruby applications"><p><a href="http://gembundler.com/bundle_install.html">Bundler: The best way to manage Ruby applications</a></p>
<p>Install all gems into vendor/bundle, even gems that are already installed to your system and would normally be used from there instead of installed.</p></blockquote>
<p>インストール時にnative extensionが作られるgem(たとえばsqlite3-ruby)をBundlerで入れるときに、おすすめされているディレクトリ(vendor/bundle)にインストールするとnativeなものがリポジトリに含まれちゃってわりと残念な感じになるんですが、みなさんどうしてるんでしょうか。<br />
いくつかのディレクトリ(cache,gems,specifications)に撒かれているのをそれぞれ.gitignoreに書くのもそれはそれで気持ち悪いのでなにかうまい方法を考えていたら日が暮れてしまうという始末。あーなんてこと！</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/08/21/182150.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RailsでBase64を。</title>
		<link>http://saikyoline.jp/weblog/2010/06/30/012837.html</link>
		<comments>http://saikyoline.jp/weblog/2010/06/30/012837.html#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:28:37 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=996</guid>
		<description><![CDATA[改行とるのをベタ実装してたらメソッドあったという話。 activesupport-2.3.8/lib/active_support/core_ext/base64/encoding.rb 10 def encode64s [...]]]></description>
			<content:encoded><![CDATA[<p>改行とるのをベタ実装してたらメソッドあったという話。</p>
<p><em><a href="http://github.com/rails/rails/blob/v2.3.8/activesupport/lib/active_support/core_ext/base64/encoding.rb">activesupport-2.3.8/lib/active_support/core_ext/base64/encoding.rb</a></em></p>
<pre class="code"><code> 10         def encode64s(value)
 11           encode64(value).gsub(/\n/, '')
 12         end</code></pre>
<p>ほっほー。</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/06/30/012837.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>本を書きました。</title>
		<link>http://saikyoline.jp/weblog/2010/04/23/012541.html</link>
		<comments>http://saikyoline.jp/weblog/2010/04/23/012541.html#comments</comments>
		<pubDate>Thu, 22 Apr 2010 16:25:41 +0000</pubDate>
		<dc:creator>yoshuki</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://saikyoline.jp/weblog/?p=979</guid>
		<description><![CDATA[Ruby on Rails携帯サイト開発技法ソフトバンククリエイティブ(2010-04-30)ソフトバンククリエイティブ新品価格：￥ 2,940ASIN：4797358785 自分はjpmobileを使ってアプリを作る章 [...]]]></description>
			<content:encoded><![CDATA[<table style="border: 1px dotted #999999; font-size: 14px; margin: 5px; text-align: left;">
<tr>
<td><a href="http://amazon.jp/dp/4797358785/saikyoline-22"><img src="http://ecx.images-amazon.com/images/I/51JwLD%2BqNiL._SL160_.jpg" width="126" height="160" alt="Ruby on Rails携帯サイト開発技法" title="Ruby on Rails携帯サイト開発技法" style="border: 0px; margin: 5px 10px 5px 5px;"/></a></td>
<td><a href="http://amazon.jp/dp/4797358785/saikyoline-22" style="text-decoration: none;"><span style="font-weight: bold;">Ruby on Rails携帯サイト開発技法</span><br/><span>ソフトバンククリエイティブ(2010-04-30)</span><br/><span>ソフトバンククリエイティブ</span><br/><span>新品価格：￥ 2,940</span><br/><span>ASIN：4797358785</span></a></td>
</tr>
</table>
<p>自分はjpmobileを使ってアプリを作る章を担当しました。書店で見かけたら手にとって頂けるとありがたいです。</p>
]]></content:encoded>
			<wfw:commentRss>http://saikyoline.jp/weblog/2010/04/23/012541.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

