<?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>TechRacho</title>
	<atom:link href="http://techracho.bpsinc.jp/feed" rel="self" type="application/rss+xml" />
	<link>http://techracho.bpsinc.jp</link>
	<description>最新の技術トレンド＆ITに関するアイデアマガジン</description>
	<lastBuildDate>Fri, 18 May 2012 01:06:17 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>paperclipでsave前のattachmentをコピーする</title>
		<link>http://techracho.bpsinc.jp/baba/2012_05_18/5517?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=paperclip%25e3%2581%25a7save%25e5%2589%258d%25e3%2581%25aeattachment%25e3%2582%2592%25e3%2582%25b3%25e3%2583%2594%25e3%2583%25bc%25e3%2581%2599%25e3%2582%258b</link>
		<comments>http://techracho.bpsinc.jp/baba/2012_05_18/5517#comments</comments>
		<pubDate>Fri, 18 May 2012 01:06:17 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>
		<category><![CDATA[paperclip]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5517</guid>
		<description><![CDATA[多少レアケースだと思いますが、paperclipでセットしたattachmentを、save前に他のインスタンスにコピーしたいことがありました。 単純にセットしただけでは、@user1.avatar.file?がtrueを返すものの本来のパスに保存されていないので、エラーになってしまいます。 class User &#60; ActiveRecoed::Base has_attached_file :avatar end @user1 = User.new(params&#91;:user&#93;) @user2 = User.new @user2.avatar = @user1.avatar @user2.save! # ここでfile not foundなエラーが出る paperclipでは、saveする前のtempfileはattachmentの@queued_for_write[:original]の@tempfileとして保存されているようです（ActionDispatch::Http::UploadedFileとして登録された場合）。 今回はライブラリ用だったので、かなりバージョン依存強くてよろしくないのですが、このような感じに。 def copy_attributes_to(target) target.assign_attributes attributes.reject { &#124;k, v&#124; &#91;self.class.primary_key, 'created_at', 'updated_at'&#93;.include?(k) } if respond_to?(:each_attachment) each_attachment do &#8230; <a href="http://techracho.bpsinc.jp/baba/2012_05_18/5517">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>多少レアケースだと思いますが、paperclipでセットしたattachmentを、save前に他のインスタンスにコピーしたいことがありました。</p>
<p>単純にセットしただけでは、@user1.avatar.file?がtrueを返すものの本来のパスに保存されていないので、エラーになってしまいます。</p>
<pre class="brush:ruby">
class User &#60; ActiveRecoed::Base
  has_attached_file :avatar
end

@user1 = User.new(params&#91;:user&#93;)
@user2 = User.new
@user2.avatar = @user1.avatar
@user2.save! # ここでfile not foundなエラーが出る
</pre>
<p>paperclipでは、saveする前のtempfileはattachmentの@queued_for_write[:original]の@tempfileとして保存されているようです（ActionDispatch::Http::UploadedFileとして登録された場合）。</p>
<p>今回はライブラリ用だったので、かなりバージョン依存強くてよろしくないのですが、このような感じに。</p>
<pre class="brush:ruby">
def copy_attributes_to(target)
  target.assign_attributes attributes.reject { |k, v|
    &#91;self.class.primary_key, 'created_at', 'updated_at'&#93;.include?(k)
  }
  if respond_to?(:each_attachment)
    each_attachment do |n, a|
      if a.dirty?
        file = a.queued_for_write&#91;:original&#93;.instance_variable_get(:@tempfile)
      elsif a.file?
        file = a
      else
        file = nil
      end
      target.attachment_for(n).assign file
    end
  end
end
</pre>
<p>二重にコピーすると2回目はio_adapterがattachment_adapterになるので動かなかったり、たぶんバージョン上がると動かなかったりするので、改善したいと思いつつ、とりあえず上記で動いています。<br />
Ruby 1.9.3 + Rails 3.2.3 + paperclip 3.0.3</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/baba/2012_05_18/5517/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>redmineで複数リポジトリを登録したらリポジトリや設定ページが500エラー</title>
		<link>http://techracho.bpsinc.jp/baba/2012_05_17/5510?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=redmine%25e3%2581%25a7%25e8%25a4%2587%25e6%2595%25b0%25e3%2583%25aa%25e3%2583%259d%25e3%2582%25b8%25e3%2583%2588%25e3%2583%25aa%25e3%2582%2592%25e7%2599%25bb%25e9%258c%25b2%25e3%2581%2597%25e3%2581%259f%25e3%2582%2589%25e3%2583%25aa%25e3%2583%259d%25e3%2582%25b8%25e3%2583%2588%25e3%2583%25aa%25e3%2582%2584%25e8%25a8%25ad</link>
		<comments>http://techracho.bpsinc.jp/baba/2012_05_17/5510#comments</comments>
		<pubDate>Thu, 17 May 2012 02:56:24 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[ITライフ]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ビジネス]]></category>
		<category><![CDATA[redmine]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5510</guid>
		<description><![CDATA[redmine 1.3では、リポジトリを複数設定できて便利になりましたね。 開発者以外にgitリポジトリを見せるのは地味に面倒なので、redmineに統合されているのは助かります。 gitはsvnと違って部分チェックアウトが出来ないぶん、複数リポジトリ登録機能は必須です。 さて今回は、1プロジェクトに3つめのリポジトリを設定したら、500 Internal Server Errorになってしまいました。 ログを見ると以下のようになっています。 ActionView::TemplateError (undefined method `' for nil:NilClass) on line #64 of app/views/repositories/show.html.erb: 61: 1 %> 62: 63: 64: 'repositories', :action => 'show', :id => @project, :repository_id => repo.identifier_param, :rev => nil, :path &#8230; <a href="http://techracho.bpsinc.jp/baba/2012_05_17/5510">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>redmine 1.3では、リポジトリを複数設定できて便利になりましたね。</p>
<p>開発者以外にgitリポジトリを見せるのは地味に面倒なので、redmineに統合されているのは助かります。<br />
gitはsvnと違って部分チェックアウトが出来ないぶん、複数リポジトリ登録機能は必須です。</p>
<p>さて今回は、1プロジェクトに3つめのリポジトリを設定したら、500 Internal Server Errorになってしまいました。<br />
ログを見ると以下のようになっています。</p>
<blockquote><p><code><br />
ActionView::TemplateError (undefined method `<=>' for nil:NilClass) on line #64 of app/views/repositories/show.html.erb:<br />
61: <% if @repositories.size > 1 %><br />
62:     <% content_for :sidebar do %><br />
63:<br />
<h3><%= l(:label_repository_plural) %></h3>
<p>64:       <%= @repositories.sort.collect {|repo|<br />
65:             link_to h(repo.name),<br />
66:                   {:controller => 'repositories', :action => 'show', :id => @project, :repository_id => repo.identifier_param, :rev => nil, :path => nil},<br />
67:                   :class => 'repository' + (repo == @repository ? ' selected' : '')</p>
<p>    app/models/repository.rb:144:in `<=>'<br />
    app/views/repositories/show.html.erb:64<br />
    app/helpers/application_helper.rb:1017:in `content_for'<br />
    app/views/repositories/show.html.erb:62<br />
    app/controllers/repositories_controller.rb:102:in `show'<br />
</code></p></blockquote>
<p>原因は、メインで無いのにidentifierがnilのrepositoriesレコードが存在したこと。並び替えの部分でnilエラーが出ていますね。</p>
<p>今回は以下のようなSQL文で回避しました。<br />
<code>UPDATE repositories SET identifier = 'sub_repository_1' WHERE id = 81;</code></p>
<p>修正パッチを送ろうと思ったら、既に修正済みみたいです。<br />
<a href="http://www.redmine.org/issues/10827">http://www.redmine.org/issues/10827</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/baba/2012_05_17/5510/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symbol not found: _rb_Digest_SHA1_Finish (LoadError)</title>
		<link>http://techracho.bpsinc.jp/annotunzdy/2012_05_16/5526?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=5526</link>
		<comments>http://techracho.bpsinc.jp/annotunzdy/2012_05_16/5526#comments</comments>
		<pubDate>Wed, 16 May 2012 09:22:12 +0000</pubDate>
		<dc:creator>annotunzdy</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5526</guid>
		<description><![CDATA[Mac OS 10.7.3環境で、rvmを使ってruby 1.9.3を入れたところ、 以下のエラーで、bundle install出来ませんでした。 [shell] Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Please include the full output of the command, your Gemfile &#8230; <a href="http://techracho.bpsinc.jp/annotunzdy/2012_05_16/5526">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Mac OS 10.7.3環境で、rvmを使ってruby 1.9.3を入れたところ、<br />
以下のエラーで、bundle install出来ませんでした。</p>
<p>[shell]<br />
Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Please include the full output of the command, your Gemfile and Gemfile.lock. Thanks!<br />
/Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require&#8217;: dlopen(/Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle, 9): Symbol not found: _rb_Digest_SHA1_Finish (LoadError)<br />
  Referenced from: /Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle<br />
  Expected in: flat namespace<br />
 in /Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle &#8211; /Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle<br />
	from /Users/annotunzdy/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:1:in `<top (required)>&#8216;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler.rb:135:in `definition&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/cli.rb:220:in `install&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/task.rb:22:in `run&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor.rb:263:in `dispatch&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/base.rb:386:in `start&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/bin/bundle:13:in `<top (required)>&#8216;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle:19:in `load&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle:19:in `<main>&#8216;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/bin/ruby_noexec_wrapper:14:in `eval&#8217;<br />
	from /Users/annotunzdy/.rvm/gems/ruby-1.9.3-p194@global/bin/ruby_noexec_wrapper:14:in `<main>&#8216;<br />
[/shell]</p>
<p>色々試したところ、<a href="http://bugs.ruby-lang.org/issues/6033">Ruby 1.9.3のsha1.bundleのバグ</a><br />
が原因であることがわかりました。</p>
<p>そこで、以下のコマンドで、ruby 1.9.2のsha1.bundleを、1.9.3のディレクトリにコピーすることで解決しました。</p>
<p>[shell]<br />
mv &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle&#8221; &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle.bak&#8221;<br />
cp &#8220;$HOME/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle&#8221; &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest/sha1.bundle&#8221;<br />
[/shell]</p>
<p>(追記) sha1.bundle以外のbundleにも問題があることがわかりました。<br />
　　　以下のように、digestフォルダ丸ごとコピーしたほうがより安全です。</p>
<p>[shell]<br />
mv &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest&#8221; &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest.bak&#8221;<br />
cp -R &#8220;$HOME/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest&#8221; &#8220;$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.3.0/digest&#8221;<br />
[/shell]</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/annotunzdy/2012_05_16/5526/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>複数台APPサーバ構成の時にdevise_openid_authenticatableで認証できない</title>
		<link>http://techracho.bpsinc.jp/baba/2012_05_16/5470?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e8%25a4%2587%25e6%2595%25b0%25e5%258f%25b0app%25e3%2582%25b5%25e3%2583%25bc%25e3%2583%2590%25e6%25a7%258b%25e6%2588%2590%25e3%2581%25ae%25e6%2599%2582%25e3%2581%25abdevise_openid_authenticatable%25e3%2581%25a7%25e8%25aa%258d%25e8%25a8%25bc%25e3%2581%25a7%25e3%2581%258d%25e3%2581%25aa%25e3%2581%2584</link>
		<comments>http://techracho.bpsinc.jp/baba/2012_05_16/5470#comments</comments>
		<pubDate>Wed, 16 May 2012 01:56:54 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>
		<category><![CDATA[devise]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[複数台]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5470</guid>
		<description><![CDATA[devise_openid_authenticatableを使うと、Deviseと親和性高くOpenIDログインを実現できて便利です。 devise_openid_authenticatableは、内部でRack::OpenIDを使用しています。 これは、デフォルトではアプリケーションサーバが複数台の場合に動作しないので、注意が必要です。 これは、ソースコードのコメントに書いてあるとおり、OpenIDによる認証の際にStoreとしてMemoryを使っているのが原因です。 （OpenID認証では、ユーザをいったん別サイトに飛ばすので、戻ってきたときのためにデータを保持しておく必要があります。 # Initialize middleware with application and optional OpenID::Store. # If no store is given, OpenID::Store::Memory is used. # # use Rack::OpenID # # or # # use Rack::OpenID, OpenID::Store::Memcache.new https://github.com/josh/rack-openid/blob/master/lib/rack/openid.rb たとえばアプリ2台のラウンドロビンの場合、このままでは、正しくOpenID認証しても1/2の確率でしかログインできません。 IPベースでAPPサーバの振り分けを制御すれば動作しないこともないですが、リクエストごとにIP変わるようなこともあるので、すべてのAPPサーバでOpenID::Storeを共有できる設定にしておきましょう。 memcachedサーバを使う場合の設定例は以下のような感じです。 # config/environments/production.rb &#8230; <a href="http://techracho.bpsinc.jp/baba/2012_05_16/5470">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>devise_openid_authenticatableを使うと、Deviseと親和性高くOpenIDログインを実現できて便利です。</p>
<p>devise_openid_authenticatableは、内部でRack::OpenIDを使用しています。<br />
これは、デフォルトではアプリケーションサーバが複数台の場合に動作しないので、注意が必要です。</p>
<p>これは、ソースコードのコメントに書いてあるとおり、OpenIDによる認証の際にStoreとしてMemoryを使っているのが原因です。<br />
（OpenID認証では、ユーザをいったん別サイトに飛ばすので、戻ってきたときのためにデータを保持しておく必要があります。</p>
<blockquote><p>
# Initialize middleware with application and optional OpenID::Store.<br />
# If no store is given, OpenID::Store::Memory is used.<br />
#<br />
#   use Rack::OpenID<br />
#<br />
# or<br />
#<br />
#   use Rack::OpenID, OpenID::Store::Memcache.new
</p></blockquote>
<p><a href="https://github.com/josh/rack-openid/blob/master/lib/rack/openid.rb">https://github.com/josh/rack-openid/blob/master/lib/rack/openid.rb</a></p>
<p>たとえばアプリ2台のラウンドロビンの場合、このままでは、正しくOpenID認証しても1/2の確率でしかログインできません。</p>
<p>IPベースでAPPサーバの振り分けを制御すれば動作しないこともないですが、リクエストごとにIP変わるようなこともあるので、すべてのAPPサーバでOpenID::Storeを共有できる設定にしておきましょう。<br />
memcachedサーバを使う場合の設定例は以下のような感じです。</p>
<pre class="brush:ruby">
# config/environments/production.rb
config.middleware.insert_before(
  Warden::Manager,
  Rack::OpenID,
  OpenID::Store::Memcache.new(MemCache.new('192.168.0.123:11211'))
)
</pre>
<p><small>この記事の元ネタは<a href="http://techracho.bpsinc.jp/author/morimorihoge">morimorihoge</a>に教えてもらいました。</small></p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/baba/2012_05_16/5470/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 失敗しないmigrationを書こう</title>
		<link>http://techracho.bpsinc.jp/baba/2012_05_15/5462?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rails-%25e5%25a4%25b1%25e6%2595%2597%25e3%2581%2597%25e3%2581%25aa%25e3%2581%2584migration%25e3%2582%2592%25e6%259b%25b8%25e3%2581%2593%25e3%2581%2586</link>
		<comments>http://techracho.bpsinc.jp/baba/2012_05_15/5462#comments</comments>
		<pubDate>Tue, 15 May 2012 02:07:01 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5462</guid>
		<description><![CDATA[migrationは、いったん他の人と共有してしまったら、容易に変更できず、基本的に追加するのみです。 うっかり環境依存なmigrationを書いてしまっても、自分や既に開発しているメンバーは気づかないことが多いのですが、 新メンバーが参加したり、本番デプロイ環境を整備したときに初めて問題に気づくことがあります。 CI環境で問題の早期発見を目指すのはもちろんですが、事前にやりがちなポイントは気をつけておきましょう。 ライブラリのmigration用メソッドに依存しない たとえばdeviseの旧バージョンでは、 t.confirmable などのメソッドを使用していましたが、これは最新版ではDEPRECATEDになっています。 また、t.authenticatableを使用した際、バージョンによりpassword_saltが自動生成されるものとされないものがあります。 プロジェクト開始時からライブラリのバージョンを上げた場合、このようなメソッドを使っていると、エラーになったり生成されるカラムが変更されたりするので、データベースに矛盾が生じてしまいます。 特に理由が無ければ、 t.string :password のように標準機能で記述するのがおすすめです。 モデルクラスを使わない migration内でデータの検査や変更をする場合など、ActiveRecordのモデルを使いたくなりますが、これは危険です。 migrationは基本的にずっと残るので、仮に将来そのモデルファイルが削除された場合、rake db:migrate:resetが通らなくなってしまいます。 SQLを直接使用するか、以下のように一時的にActiveRecord::Baseを継承したクラスを作るなどの対策が必要です。 Object.const_set "User", Class.new(ActiveRecord::Base) インデックスの長さに注意する add_indexでリンクを張る際、長いテーブル名では、気をつけないと64文字を超えてしまうことがあります。 MySQLでは、インデックス名は基本的に64文字以下にする必要がありますが、バージョンによってはそれ以上でも通るので、気づくのが遅れると面倒なことになることがあります。 事前に、長いテーブルやカラム名の場合、インデックスには名前を付けておきましょう。 # 例: MangaRebornでは、投稿されたファンアートや翻訳をすぐに公開するかどうか、選択することができます. 仮に複合インデックスを張るとすると、64文字を超えます add_index, :manga_artists, [:allow_publish_fan_art_immediately, :allow_publish_translation_immediately], :name => 'index_manga_artists_1 downをちゃんと書く 当然ですが、downをちゃんと書きましょう。 Rails &#8230; <a href="http://techracho.bpsinc.jp/baba/2012_05_15/5462">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>migrationは、いったん他の人と共有してしまったら、容易に変更できず、基本的に追加するのみです。</p>
<p>うっかり環境依存なmigrationを書いてしまっても、自分や既に開発しているメンバーは気づかないことが多いのですが、<br />
新メンバーが参加したり、本番デプロイ環境を整備したときに初めて問題に気づくことがあります。</p>
<p>CI環境で問題の早期発見を目指すのはもちろんですが、事前にやりがちなポイントは気をつけておきましょう。</p>
<h3>ライブラリのmigration用メソッドに依存しない</h3>
<p>たとえば<a href="https://github.com/plataformatec/devise">devise</a>の旧バージョンでは、<br />
<code>t.confirmable</code><br />
などのメソッドを使用していましたが、これは最新版ではDEPRECATEDになっています。<br />
また、<code>t.authenticatable</code>を使用した際、バージョンによりpassword_saltが自動生成されるものとされないものがあります。</p>
<p>プロジェクト開始時からライブラリのバージョンを上げた場合、このようなメソッドを使っていると、エラーになったり生成されるカラムが変更されたりするので、データベースに矛盾が生じてしまいます。<br />
特に理由が無ければ、<br />
<code>t.string :password</code><br />
のように標準機能で記述するのがおすすめです。</p>
<h3>モデルクラスを使わない</h3>
<p>migration内でデータの検査や変更をする場合など、ActiveRecordのモデルを使いたくなりますが、これは危険です。<br />
migrationは基本的にずっと残るので、仮に将来そのモデルファイルが削除された場合、rake db:migrate:resetが通らなくなってしまいます。<br />
SQLを直接使用するか、以下のように一時的にActiveRecord::Baseを継承したクラスを作るなどの対策が必要です。<br />
<code>Object.const_set "User", Class.new(ActiveRecord::Base)</code></p>
<h3>インデックスの長さに注意する</h3>
<p><code>add_index</code>でリンクを張る際、長いテーブル名では、気をつけないと64文字を超えてしまうことがあります。<br />
MySQLでは、インデックス名は基本的に64文字以下にする必要がありますが、バージョンによってはそれ以上でも通るので、気づくのが遅れると面倒なことになることがあります。<br />
事前に、長いテーブルやカラム名の場合、インデックスには名前を付けておきましょう。<br />
<code><br />
# 例: MangaRebornでは、投稿されたファンアートや翻訳をすぐに公開するかどうか、選択することができます. 仮に複合インデックスを張るとすると、64文字を超えます<br />
add_index, :manga_artists, [:allow_publish_fan_art_immediately, :allow_publish_translation_immediately], :name => 'index_manga_artists_1<br />
</code></p>
<h3>downをちゃんと書く</h3>
<p>当然ですが、downをちゃんと書きましょう。<br />
Rails 3.1以降ではchangeが使えますが、これはcreate/add系で自動処理してくれるだけなので、change_columnやremove_columnの時は正しくdownを書く必要があります。<br />
db:migrate:redoをやってからコミットすれば安心ですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/baba/2012_05_15/5462/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【Rails】ajax内のflashが出続ける！？</title>
		<link>http://techracho.bpsinc.jp/kazumasa-ogawa/2012_05_14/5503?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e3%2580%2590rails%25e3%2580%2591ajax%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%25a3%25e3%2581%25a6%25e3%2581%2584%25e3%2582%258b%25e3%2581%25a8flash%25e3%2581%258c%25e5%2587%25ba%25e7%25b6%259a%25e3%2581%2591%25e3%2582%258b%25ef%25bc%2581%25ef%25bc%259f</link>
		<comments>http://techracho.bpsinc.jp/kazumasa-ogawa/2012_05_14/5503#comments</comments>
		<pubDate>Mon, 14 May 2012 10:39:01 +0000</pubDate>
		<dc:creator>Kazumasa Ogawa</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5503</guid>
		<description><![CDATA[小川です。 Railsのflashメッセージをajaxで出すと他のページに遷移しても、更新してもて続けるという状況に遭遇しました。 1度だけ出てくれればいいんですけど。。。 下記がajaxで表示する部分です。下記のファイルパスが(front_ajax_path) [ruby] [/ruby] flashを表示させたいビュー [html] [/html] 実行しているajax [javascript] $(&#8216;#notice_or_alert_for_ajax_area&#8217;).load(&#8220;&#8220;); [/javascript] 解決策 application_controllerに以下を記述して明示的にアクション実行後にflash消すようにしました。 if request.xhrでajaxからのリクエストかどうか判定しています。 [ruby] after_filter :discard_flash_if_xhr [/ruby] [ruby] protected def discard_flash_if_xhr flash.discard if request.xhr? end [/ruby]]]></description>
			<content:encoded><![CDATA[<p>小川です。</p>
<p>Railsのflashメッセージをajaxで出すと他のページに遷移しても、更新してもて続けるという状況に遭遇しました。<br />
1度だけ出てくれればいいんですけど。。。</p>
<p>下記がajaxで表示する部分です。下記のファイルパスが(front_ajax_path)<br />
[ruby]</p>
<p style="font-size:16px; font-weight:bold;"><%= flash[:notice] %></p>
<p>[/ruby]</p>
<p>flashを表示させたいビュー<br />
[html]</p>
<div id="notice_or_alert_for_ajax_area"></div>
<p>[/html]</p>
<p>実行しているajax<br />
[javascript]<br />
$(&#8216;#notice_or_alert_for_ajax_area&#8217;).load(&#8220;<%= front_ajax_path %>&#8220;);<br />
[/javascript]</p>
<p>解決策<br />
application_controllerに以下を記述して明示的にアクション実行後にflash消すようにしました。<br />
if request.xhrでajaxからのリクエストかどうか判定しています。<br />
[ruby]<br />
after_filter :discard_flash_if_xhr<br />
[/ruby]<br />
[ruby]<br />
protected<br />
  def discard_flash_if_xhr<br />
    flash.discard if request.xhr?<br />
  end<br />
[/ruby]</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/kazumasa-ogawa/2012_05_14/5503/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsでDBからFixtureを作成する</title>
		<link>http://techracho.bpsinc.jp/baba/2012_05_14/5456?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rails%25e3%2581%25a7db%25e3%2581%258b%25e3%2582%2589fixture%25e3%2582%2592%25e4%25bd%259c%25e6%2588%2590%25e3%2581%2599%25e3%2582%258b</link>
		<comments>http://techracho.bpsinc.jp/baba/2012_05_14/5456#comments</comments>
		<pubDate>Mon, 14 May 2012 01:48:44 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web開発]]></category>
		<category><![CDATA[fixture]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5456</guid>
		<description><![CDATA[fixtureを手で作るのはとても疲れるので、DBから自動生成したり、FactoryGirlをはじめとしたFixture alternativeを使うことが多いと思います。 DBからfixtureのYAMLを生成する方法は色々見つかりますが、今回は要件を満たすものが見つからなかったので、rakeタスクを作ってみました。 複数行テキストやコロン(:)が含まれるテキストを、正しく処理できないものが多いんですよね。 今回はこのような要件を満たすようにしました。 MySQLで動作する テーブルを指定できる 複数行のテキストフィールドを処理できる IDやモデルファイルが無いテーブル（HABTM用中間テーブルなど）に対応する 以下のようなファイルを、lib/tasks/extract_fixtures.rakeとして保存し、 rake db:fixtures:extract すると、tmp/fixtures以下にテーブルごとのYAMLファイルが生成されるので、問題なさそうならspec/fixturesにmvすればOKです。 MySQLのDATETIME型でNOT NULLを指定した際など、0000-00-00といった値が入っている場合があり、これはActiveRecordを通すとnilになります。 このままYAMLにすると、fixtureを使うときに ActiveRecord::StatementInvalid column &#8216;date&#8217; cannot be null などのエラーが発生してしまいます。そのため、NOT NULLカラムでNULLが見つかった場合は、空文字に変換しています。]]></description>
			<content:encoded><![CDATA[<p>fixtureを手で作るのはとても疲れるので、DBから自動生成したり、FactoryGirlをはじめとしたFixture alternativeを使うことが多いと思います。</p>
<p>DBからfixtureのYAMLを生成する方法は色々見つかりますが、今回は要件を満たすものが見つからなかったので、rakeタスクを作ってみました。<br />
複数行テキストやコロン(:)が含まれるテキストを、正しく処理できないものが多いんですよね。</p>
<p>今回はこのような要件を満たすようにしました。</p>
<ul>
<li>MySQLで動作する</li>
<li>テーブルを指定できる</li>
<li>複数行のテキストフィールドを処理できる</li>
<li>IDやモデルファイルが無いテーブル（HABTM用中間テーブルなど）に対応する</li>
</ul>
<p>以下のようなファイルを、lib/tasks/extract_fixtures.rakeとして保存し、<br />
<code>rake db:fixtures:extract</code><br />
すると、tmp/fixtures以下にテーブルごとのYAMLファイルが生成されるので、問題なさそうならspec/fixturesにmvすればOKです。</p>
<div id="gist-2686783" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1"># -*- coding: utf-8 -*-</span></div><div class='line' id='LC2'><span class="c1"># DBからデータを取り出してYAMLにする。生成したYAMLはtmp/fixturesに保存される</span></div><div class='line' id='LC3'><span class="n">namespace</span> <span class="ss">:db</span> <span class="k">do</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="n">namespace</span> <span class="ss">:fixtures</span> <span class="k">do</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">desc</span> <span class="s2">&quot;Extract database data to tmp/fixtures directory.&quot;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">task</span> <span class="ss">:extract</span> <span class="o">=&gt;</span> <span class="ss">:environment</span> <span class="k">do</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">fixtures_dir</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Rails</span><span class="o">.</span><span class="n">root</span><span class="si">}</span><span class="s2">/tmp/fixtures/&quot;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">skip_tables</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;schema_info&quot;</span><span class="p">,</span> <span class="s2">&quot;schema_migrations&quot;</span><span class="p">,</span> <span class="s2">&quot;sessions&quot;</span><span class="o">]</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">establish_connection</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">mkdir_p</span><span class="p">(</span><span class="n">fixtures_dir</span><span class="p">)</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;FIXTURES&#39;</span><span class="o">]</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">table_names</span> <span class="o">=</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;FIXTURES&#39;</span><span class="o">].</span><span class="n">split</span><span class="p">(</span><span class="sr">/,/</span><span class="p">)</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">table_names</span> <span class="o">=</span> <span class="p">(</span><span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">tables</span> <span class="o">-</span> <span class="n">skip_tables</span><span class="p">)</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">table_names</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">table_name</span><span class="o">|</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">begin</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">model</span> <span class="o">=</span> <span class="n">table_name</span><span class="o">.</span><span class="n">classify</span><span class="o">.</span><span class="n">constantize</span> <span class="c1"># check class existing</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">rescue</span> <span class="no">NameError</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">Object</span><span class="o">.</span><span class="n">const_set</span> <span class="n">table_name</span><span class="o">.</span><span class="n">classify</span><span class="p">,</span> <span class="no">Class</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="no">ApplicationModel</span><span class="p">)</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">retry</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">any?</span><span class="p">{</span><span class="o">|</span><span class="n">c</span><span class="o">|</span> <span class="n">c</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;id&#39;</span><span class="p">}</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">sql</span> <span class="o">=</span> <span class="s2">&quot;SELECT * FROM </span><span class="si">#{</span><span class="n">table_name</span><span class="si">}</span><span class="s2"> ORDER BY id ASC&quot;</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">sql</span> <span class="o">=</span> <span class="s2">&quot;SELECT * FROM </span><span class="si">#{</span><span class="n">table_name</span><span class="si">}</span><span class="s2">&quot;</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">fixtures_dir</span><span class="si">}#{</span><span class="n">table_name</span><span class="si">}</span><span class="s2">.yml&quot;</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">file</span><span class="o">|</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">objects</span> <span class="o">=</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">select_all</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">objects</span><span class="o">.</span><span class="n">each_with_index</span> <span class="k">do</span> <span class="o">|</span><span class="n">obj</span><span class="p">,</span> <span class="n">i</span><span class="o">|</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># not nullのカラムがnullになっていることがあるので、その場合は空文字列を入れておく</span></div><div class='line' id='LC34'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">model</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">col</span><span class="o">|</span></div><div class='line' id='LC35'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="o">!</span><span class="n">col</span><span class="o">.</span><span class="n">null</span> <span class="o">&amp;&amp;</span> <span class="n">obj</span><span class="o">[</span><span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">].</span><span class="n">nil?</span></div><div class='line' id='LC36'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">obj</span><span class="o">[</span><span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span></div><div class='line' id='LC37'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC38'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">file</span><span class="o">.</span><span class="n">write</span><span class="p">({</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">table_name</span><span class="si">}#{</span><span class="n">i</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">=&gt;</span> <span class="n">obj</span><span class="p">}</span><span class="o">.</span><span class="n">to_yaml</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">&#39;---&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">))</span></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">file</span><span class="o">.</span><span class="n">write</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">puts</span> <span class="s2">&quot;extracted </span><span class="si">#{</span><span class="n">table_name</span><span class="si">}</span><span class="s2">&quot;</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC46'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC47'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2686783/7bcdba480de8c758fcb46461797d8032f6828e0e/extract_fixtures.rake" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2686783#file_extract_fixtures.rake" style="float:right;margin-right:10px;color:#666">extract_fixtures.rake</a>
            <a href="https://gist.github.com/2686783">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>MySQLのDATETIME型でNOT NULLを指定した際など、0000-00-00といった値が入っている場合があり、これはActiveRecordを通すとnilになります。<br />
このままYAMLにすると、fixtureを使うときに</p>
<blockquote><p>
ActiveRecord::StatementInvalid column &#8216;date&#8217; cannot be null
</p></blockquote>
<p>などのエラーが発生してしまいます。そのため、NOT NULLカラムでNULLが見つかった場合は、空文字に変換しています。</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/baba/2012_05_14/5456/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ステージング用の、ブラックホールSMTPサーバー2(Postfix編)</title>
		<link>http://techracho.bpsinc.jp/yamasita-taisuke/2012_05_14/5477?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e3%2582%25b9%25e3%2583%2586%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25b3%25e3%2582%25b0%25e7%2594%25a8%25e3%2581%25ae%25e3%2580%2581%25e3%2583%2596%25e3%2583%25a9%25e3%2583%2583%25e3%2582%25af%25e3%2583%259b%25e3%2583%25bc%25e3%2583%25absmtp%25e3%2582%25b5%25e3%2583%25bc%25e3%2583%2590%25e3%2583%25bc2postfix</link>
		<comments>http://techracho.bpsinc.jp/yamasita-taisuke/2012_05_14/5477#comments</comments>
		<pubDate>Sun, 13 May 2012 15:54:01 +0000</pubDate>
		<dc:creator>yamasita</dc:creator>
				<category><![CDATA[サーバー/ネットワーク]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5477</guid>
		<description><![CDATA[はじめまして4月から中途入社で BPS株式会社に入社しました山下泰介と申します。 前職はSIerにて金融系システムの開発と保守をしていました。 サーバーが好きなので、インフラSEとして採用して頂きました。 と言ってもまだまだ修行中です。。。 なので、あんまり難しいことは書かない（書けない）です。 今後ともよろしくお願いします。 さて、一発目は佐藤先輩のブラックホールSMTPサーバーについてpostfixでやるとこんな感じ？ という設定例を書いてみます 多分、Postfixで本来のあて先と異なるアドレスに飛ばす設定は mydestinationを弄って異なるドメインを自ホストにする virtual_alias_mapsでアドレス＋ドメインごとマッピングする って方法があるのかなーと思いました 今回はユーザーについても丸ごと飛ばしたいのでvirtual_alias_mapsを使ってみます main.cf virtual_alias_maps = regexp:/etc/postfix/blackhole /etc/postfix/blackhole /^(.+&#91;@.&#93;)?bpsinc\.jp$/ root こうすれば例えばhoge@huga.bpsinc.jp宛のメールもローカルのroot宛てに届くはずです]]></description>
			<content:encoded><![CDATA[<p>はじめまして4月から中途入社で<br />
BPS株式会社に入社しました山下泰介と申します。</p>
<p>前職はSIerにて金融系システムの開発と保守をしていました。<br />
サーバーが好きなので、インフラSEとして採用して頂きました。<br />
と言ってもまだまだ修行中です。。。<br />
なので、あんまり難しいことは書かない（書けない）です。<br />
今後ともよろしくお願いします。</p>
<p>さて、一発目は<a href="http://techracho.bpsinc.jp/annotunzdy/2012_05_10/5446">佐藤先輩のブラックホールSMTPサーバー</a>についてpostfixでやるとこんな感じ？<br />
という設定例を書いてみます</p>
<p>多分、Postfixで本来のあて先と異なるアドレスに飛ばす設定は</p>
<ul>
<li>mydestinationを弄って異なるドメインを自ホストにする</li>
<li>virtual_alias_mapsでアドレス＋ドメインごとマッピングする</li>
</ul>
<p>って方法があるのかなーと思いました</p>
<p>今回はユーザーについても丸ごと飛ばしたいのでvirtual_alias_mapsを使ってみます</p>
<p>main.cf</p>
<pre>virtual_alias_maps = regexp:/etc/postfix/blackhole</pre>
<p>/etc/postfix/blackhole</p>
<pre>/^(.+&#91;@.&#93;)?bpsinc\.jp$/      root</pre>
<p>こうすれば例えばhoge@huga.bpsinc.jp宛のメールもローカルのroot宛てに届くはずです</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/yamasita-taisuke/2012_05_14/5477/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ステージング用の、ブラックホールSMTPサーバー</title>
		<link>http://techracho.bpsinc.jp/annotunzdy/2012_05_10/5446?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e3%2582%25b9%25e3%2583%2586%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25b3%25e3%2582%25b0%25e7%2594%25a8%25e3%2581%25ae%25e3%2580%2581%25e3%2583%2596%25e3%2583%25a9%25e3%2583%2583%25e3%2582%25af%25e3%2583%259b%25e3%2583%25bc%25e3%2583%25absmtp%25e3%2582%25b5%25e3%2583%25bc%25e3%2583%2590%25e3%2583%25bc</link>
		<comments>http://techracho.bpsinc.jp/annotunzdy/2012_05_10/5446#comments</comments>
		<pubDate>Wed, 09 May 2012 16:28:56 +0000</pubDate>
		<dc:creator>annotunzdy</dc:creator>
				<category><![CDATA[Web開発]]></category>
		<category><![CDATA[サーバー/ネットワーク]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[メール]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5446</guid>
		<description><![CDATA[Webアプリケーションのステージング環境において、本番データの移行などを行った場合、 誤って本番ユーザーにメールが飛ばないようにしたいことがあります。 そこで、完全にメールが飛ばない設定にすると、 今度、メール認証が必要なフロー(例:会員登録)が確認できなくて、不便です。 そこで、全てのメールをリレーせずにフックして、 開発用のメーリングリストに投げる簡単なSMTPサーバーを書いてみました。 一時的にこのSMTPサーバーを使うようにすれば、 本番ユーザーにメールが飛ぶことはなく、 かつメーリングリストで開発者には届くので便利です。 メールの送信にはGMailを使っています。 [perl] #!/usr/bin/perl use Carp; use Net::SMTP; use Net::SMTP::SSL; use Net::SMTP::Server; use Net::SMTP::Server::Client; my $to = &#8216;mailing_list@example.com&#8217;; my $gmail_account = &#8216;username&#8217;; my $gmail_password = &#8216;password&#8217;; my $server = new Net::SMTP::Server(&#8216;localhost&#8217;, 25) &#8230; <a href="http://techracho.bpsinc.jp/annotunzdy/2012_05_10/5446">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Webアプリケーションのステージング環境において、本番データの移行などを行った場合、<br />
誤って本番ユーザーにメールが飛ばないようにしたいことがあります。<br />
そこで、完全にメールが飛ばない設定にすると、<br />
今度、メール認証が必要なフロー(例:会員登録)が確認できなくて、不便です。</p>
<p>そこで、全てのメールをリレーせずにフックして、<br />
開発用のメーリングリストに投げる簡単なSMTPサーバーを書いてみました。<br />
一時的にこのSMTPサーバーを使うようにすれば、<br />
本番ユーザーにメールが飛ぶことはなく、<br />
かつメーリングリストで開発者には届くので便利です。<br />
メールの送信にはGMailを使っています。</p>
<p>[perl]<br />
#!/usr/bin/perl</p>
<p>use Carp;<br />
use Net::SMTP;<br />
use Net::SMTP::SSL;<br />
use Net::SMTP::Server;<br />
use Net::SMTP::Server::Client;</p>
<p>my $to = &#8216;mailing_list@example.com&#8217;;<br />
my $gmail_account = &#8216;username&#8217;;<br />
my $gmail_password = &#8216;password&#8217;;</p>
<p>my $server = new Net::SMTP::Server(&#8216;localhost&#8217;, 25) ||<br />
    croak(&#8220;Unable to handle client connection: $!\n&#8221;);</p>
<p>while($conn = $server->accept()) {<br />
    my $client = new Net::SMTP::Server::Client($conn) ||<br />
        croak(&#8220;Unable to handle client connection: $!\n&#8221;);</p>
<p>    $client->process || next;</p>
<p>    my $smtp = Net::SMTP::SSL->new(&#8216;smtp.gmail.com&#8217;, Port => &#8217;465&#8242;, Debug => 1);<br />
    if($smtp->auth($gmail_account, $gmail_password)){<br />
    $smtp->mail($client->{FROM});<br />
    $smtp->to($to);</p>
<p>    $smtp->data();<br />
    $smtp->datasend($client->{MSG});<br />
    $smtp->dataend();<br />
    $smtp->quit;</p>
<p>    }else{<br />
      print &#8216;SMTP Server Authentication Error!!&#8217;;<br />
    }<br />
}<br />
[/perl]</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/annotunzdy/2012_05_10/5446/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>忙しい人のためのgmail活用術紹介します。IT詳しくない人でもできますよ。</title>
		<link>http://techracho.bpsinc.jp/piichan1031/2012_05_07/5434?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=%25e5%25bf%2599%25e3%2581%2597%25e3%2581%2584%25e4%25ba%25ba%25e3%2581%25ae%25e3%2581%259f%25e3%2582%2581%25e3%2581%25aegmail%25e6%25b4%25bb%25e7%2594%25a8%25e8%25a1%2593%25e7%25b4%25b9%25e4%25bb%258b%25e3%2581%2597%25e3%2581%25be%25e3%2581%2599%25e3%2580%2582it%25e8%25a9%25b3%25e3%2581%2597%25e3%2581%258f%25e3%2581%25aa</link>
		<comments>http://techracho.bpsinc.jp/piichan1031/2012_05_07/5434#comments</comments>
		<pubDate>Mon, 07 May 2012 01:40:53 +0000</pubDate>
		<dc:creator>piichan1031</dc:creator>
				<category><![CDATA[ITライフ]]></category>
		<category><![CDATA[ビジネス]]></category>
		<category><![CDATA[注目記事]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[ツール活用術]]></category>

		<guid isPermaLink="false">http://techracho.bpsinc.jp/?p=5434</guid>
		<description><![CDATA[忙しい人のためのツール活用方法を紹介します。 今回はスタッフからお願いされたGMAILにします。 毎日大量のメールが届く人も、別それほどでもないって人も、 GMAILを使える環境があるならば処理効率を高められますよ。 皆使い方はそれぞれですし向き不向きもあると思いますが、 すくなくともカスタマイズ無しの状態よりは良いです。 Gmail Settings -> Labs 設定 まずはLabsの設定から。好みもあるので遊んでみてください。 詳細は自身で確認して、Enableに （有効にする）してください。 設定画面を開いてLabsを選択してください Background Send　日本語だと「バックグラウンドで送信」 作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。Enableすると送信中に次のメールの確認や作成ができます。 Default &#8220;Reply to all&#8221;　日本語だと「常に全員に返信」 作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。EnableするとTO/CCに入れている全員に返信してくれます。 Move Icon Column　日本語だと「アイコン欄を移動する」 作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。Enableすると見やすくなる（ような気がする）だけです。 Send and Archive　日本語だと「送信 ＆ アーカイブ」 こちらは騙されたとおもってEnableにしてください。メールを返信と同時にアーカイブ（受信箱では非表示にする）してくれます。 Multiple Inboxes　日本語だと「マルチ受信トレイ」 こちらも騙されたとおもってEnableにしてください。初期表示する受信トレイを複数作ることができます。 Gmail Settings -> Multiple &#8230; <a href="http://techracho.bpsinc.jp/piichan1031/2012_05_07/5434">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://techracho.bpsinc.jp/wp-content/uploads/2012/05/gmail-logo.png"><img src="http://techracho.bpsinc.jp/wp-content/uploads/2012/05/gmail-logo.png" alt="" title="gmail-logo" width="311" height="311" class="aligncenter size-full wp-image-5442" /></a></p>
<p>忙しい人のためのツール活用方法を紹介します。<br />
今回はスタッフからお願いされたGMAILにします。<br />
毎日大量のメールが届く人も、別それほどでもないって人も、<br />
GMAILを使える環境があるならば処理効率を高められますよ。<br />
皆使い方はそれぞれですし向き不向きもあると思いますが、<br />
すくなくともカスタマイズ無しの状態よりは良いです。</p>
<p><strong>Gmail Settings -> Labs 設定</strong><br />
<a href="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/lab1.png"><img src="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/lab1-400x185.png" alt="lab1" title="lab1" width="400" height="185" class="alignnone size-large wp-image-4957" /></a></p>
<p><a href="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/lab2.png"><img src="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/lab2-400x197.png" alt="lab2" title="lab2" width="400" height="197" class="alignnone size-large wp-image-4958" /></a></p>
<p>まずはLabsの設定から。好みもあるので遊んでみてください。<br />
詳細は自身で確認して、Enableに （有効にする）してください。</p>
<ol>
<li>設定画面を開いてLabsを選択してください</li>
<li>Background Send　日本語だと「バックグラウンドで送信」</li>
<ul>
<li>作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。Enableすると送信中に次のメールの確認や作成ができます。</li>
</ul>
<li>Default &#8220;Reply to all&#8221;　日本語だと「常に全員に返信」</li>
<ul>
<li>作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。EnableするとTO/CCに入れている全員に返信してくれます。</li>
</ul>
<li>Move Icon Column　日本語だと「アイコン欄を移動する」</li>
<ul>
<li>作業効率を上げる設定で、別にEnable（有効にする）しなくても大丈夫です。Enableすると見やすくなる（ような気がする）だけです。</li>
</ul>
<li>Send and Archive　日本語だと「送信 ＆ アーカイブ」</li>
<ul>
<li>こちらは騙されたとおもってEnableにしてください。メールを返信と同時にアーカイブ（受信箱では非表示にする）してくれます。</li>
</ul>
<li>Multiple Inboxes　日本語だと「マルチ受信トレイ」</li>
<ul>
<li>こちらも騙されたとおもってEnableにしてください。初期表示する受信トレイを複数作ることができます。</li>
</ul>
</ol>
<p><strong>Gmail Settings -> Multiple Inboxes 設定</strong><br />
<a href="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/multipleinboxes.png"><img src="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/multipleinboxes-400x201.png" alt="multipleinboxes" title="multipleinboxes" width="400" height="201" class="alignnone size-large wp-image-4969" /></a></p>
<ol>
<li>設定画面を開いてMultiple Inboxesを選択してください。</li>
<li>Pane 0 に添付と同じ文字を打ち込んでください。通常の受信箱と一緒に、★の付いたメールだけを集めた受信箱を表示してくれます。</li>
<li>表示件数はなるべく大きな数字を打ち込んで★付きのメールは全て表示するように設定します。</li>
<li>★の付いたメールだけを集めた受信箱を、通常の受信箱の下に表示するよう設定します。</li>
</ol>
<p>そうすると、下記のような画面になります。</p>
<p><strong>設定後 -> 受信トレイ</strong>　※３は別途設定が必要ですが気にしないでください<br />
<a href="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/Inbox-piichan1031@gmail.png"><img src="http://www.bpsinc.jp/plog/wp-content/uploads/2012/05/Inbox-piichan1031@gmail-400x277.png" alt="Inbox-piichan1031@gmail" title="Inbox-piichan1031@gmail" width="400" height="277" class="alignnone size-large wp-image-5115" /></a></p>
<ol>
<li>通常の受信箱
<ul>
<li><strong>未確認 or 未返信</strong> のメールはこちらに残っています。</li>
</ul>
</li>
<li>★付きのメール
<ul>
<li><strong>返信済　and　未完了</strong> のメールはこちらに残っています。</li>
</ul>
</li>
<li><strong>処理済み</strong> のメールはArchive（保管）しているので全て残っています。</li>
<li><strong>探しだす</strong> 時は検索を使います。普段必要ないものは保管だけで十分です。</li>
</ol>
<p>毎日何回もみる受信箱がメールで溢れかえっていたり<br />
すぐに対応したいものとそうでないものが混ざってたり<br />
あとで対応が求められているものが埋もれたりすると<br />
それだけで仕事が大変という気持ちになってしまいます。</p>
<p>別のTODOリストや手帳で管理するのも手ですが<br />
どうせなら普段から使っているツールで整理するのが<br />
最も効率がよくて頭への負荷が少なく本業に集中できます。</p>
<p>この考え方に同意できるかたは、<br />
対応が求められているメールに★をつけていって、<br />
その後すべてのメールを選択してArchive（保管）すると<br />
すぐにこの方法でメールが管理できるようになります。</p>
<p>お恥ずかしながら、僕の処理効率方法を紹介させていただきました。<br />
感想・アドバイス・その他Tipsなどあれば、聞かせてくださいね。　</p>
]]></content:encoded>
			<wfw:commentRss>http://techracho.bpsinc.jp/piichan1031/2012_05_07/5434/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

