<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DE8GRnozcSp7ImA9WxBQFk4.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070</id><updated>2010-01-16T19:13:47.489+09:00</updated><title>ビギナーが書くビギナーのための Rails 開発</title><subtitle type='html'>Rails 初心者が苦戦しながらサービスを立ち上げるまで</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;DE8GRnoyfSp7ImA9WxBQFk4.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-203836136842777315</id><published>2010-01-16T19:12:00.001+09:00</published><updated>2010-01-16T19:13:47.495+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-16T19:13:47.495+09:00</app:edited><title>セッションの有効期限を設定</title><content type='html'>config/initializers/session_store.rb
&lt;pre class="prettyprint"&gt;
ActionController::Base.session_options[:expire_after] = 2.hours
&lt;/pre&gt;
こんな感じ&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-203836136842777315?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/203836136842777315/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=203836136842777315' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/203836136842777315?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/203836136842777315?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/blog-post_16.html' title='セッションの有効期限を設定'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DEIEQ3c-eip7ImA9WxBQFk8.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-313904661509826161</id><published>2010-01-16T16:18:00.004+09:00</published><updated>2010-01-16T16:21:42.952+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-16T16:21:42.952+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='io'/><title>Ruby でファイルの存在をチェック</title><content type='html'>ローカルにあるファイル
&lt;pre class="prettyprint"&gt;
if File.exist?(path)
...
end
&lt;/pre&gt;

&lt;br /&gt;
リモートのファイル
&lt;pre class="prettyprint"&gt;
require 'open-uri' # environments.rb に入れちゃう
if open(URI.parse(path))
...
end
rescue # (Errno::ENOENT, OpenURI::HTTPError, etc...)などの exception を表示しない

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-313904661509826161?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/313904661509826161/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=313904661509826161' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/313904661509826161?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/313904661509826161?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/ruby.html' title='Ruby でファイルの存在をチェック'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;C0cDQnkzfip7ImA9WxBQFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-7492061452832421603</id><published>2010-01-16T00:57:00.001+09:00</published><updated>2010-01-16T00:57:53.786+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-16T00:57:53.786+09:00</app:edited><title>文字列操作</title><content type='html'>http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Chars.html#M000961&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-7492061452832421603?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/7492061452832421603/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=7492061452832421603' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7492061452832421603?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7492061452832421603?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/blog-post.html' title='文字列操作'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;A0IGRXY9cSp7ImA9WxBQFUs.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-5288304599565103947</id><published>2010-01-15T18:15:00.004+09:00</published><updated>2010-01-16T00:32:04.869+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-16T00:32:04.869+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='timezone'/><category scheme='http://www.blogger.com/atom/ns#' term='datetime'/><title>Rails datetime 設定</title><content type='html'>&lt;h4&gt;Unix timestamp を rails datetime に変更&lt;/h4&gt;
&lt;pre class="prettyprint"&gt;
@somedate = Time.at(1260519945).utc
&lt;/pre&gt;

&lt;h4&gt;DB風に表示&lt;/h4&gt;
&lt;pre class="prettyprint"&gt;
@date.to_s(:db)
# 2009-12-11 08:25:45 
&lt;/pre&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;strftime 備忘録&lt;/h4&gt;
&lt;pre class="prettyprint"&gt;
example: object.strftime("%Y/%m/%d %H:%M")  
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name 
%% - Literal ``%'' character 
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-5288304599565103947?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/5288304599565103947/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=5288304599565103947' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/5288304599565103947?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/5288304599565103947?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails-datetime.html' title='Rails datetime 設定'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;CkUCQnYyeip7ImA9WxBQEk0.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-7256994191164374603</id><published>2010-01-11T17:47:00.003+09:00</published><updated>2010-01-11T17:57:43.892+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-11T17:57:43.892+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='views'/><title>一つのフォームに複数の submit ボタンを入れる</title><content type='html'>たまに一つのフォームに複数の submit ボタンをつけて、どれをクリックするかでロジックを分けたい場合がある。

application.js
&lt;pre class="prettyprint"&gt;
function submitFormWithValue(formid, commitValue)
{
    var objForm = document.getElementById(formid);
 objForm.commit_value.value = commitValue;
 objForm.submit();
}

&lt;/pre&gt;
&lt;br /&gt;
view
&lt;pre class="prettyprint"&gt;
&lt;% form_for :req, @req, :url =&gt; {:action =&gt; :update}, :html =&gt; {:method =&gt; :put, :id =&gt; "action"} do |f| %&gt;
    &lt;input type="hidden" name="commit_value" /&gt;
    &lt;%= f.submit "Confirm", :onClick =&gt; ("return confirm('" + t('message_confirm') + "'), submitFormWithValue('action','confirm');")  %&gt;
    &lt;%= f.submit "Kill", :onClick =&gt; ("return confirm('" + t('message_kill') + "'), submitFormWithValue('action','confirm');")  %&gt;
&lt;% end %&gt;
&lt;/pre&gt;
上で return confirm はポップアップメッセージ用。:onclick を使用すると、:confirm が使えないため。&lt;br /&gt;&lt;br /&gt;

controller
&lt;pre class="prettyprint"&gt;
case params[:commit_value]
  when "confirm"
    ...
  when "kill"
    ...
end

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-7256994191164374603?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/7256994191164374603/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=7256994191164374603' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7256994191164374603?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7256994191164374603?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/submit.html' title='一つのフォームに複数の submit ボタンを入れる'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DEEBQ384fCp7ImA9WxBQEUQ.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-8032927790993377980</id><published>2010-01-11T16:55:00.002+09:00</published><updated>2010-01-11T16:57:32.134+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-11T16:57:32.134+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='i18n'/><title>Activerecord エラーメッセージの国際化</title><content type='html'>Activerecord で表示されるエラーメッセージを翻訳したいこともある。
そんな場合、デフォルトでは activerecord.errors のスコープを使う
&lt;pre class="prettyprint"&gt;
ja:
  activerecord:
    models:
      memo: メモ
    errors:
      models:
        memo:
          attributes:
            content:
             blank: 空っぽさ  
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-8032927790993377980?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/8032927790993377980/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=8032927790993377980' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/8032927790993377980?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/8032927790993377980?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/activerecord.html' title='Activerecord エラーメッセージの国際化'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;C0AASHs4fSp7ImA9WxBQEE8.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-5029963562795836863</id><published>2010-01-09T15:19:00.009+09:00</published><updated>2010-01-09T16:22:29.535+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-09T16:22:29.535+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='rjs'/><title>Ajax を使ってコメントを挿入</title><content type='html'>Ajax をつかって、記事(article)にコメント(comment)を挿入するほうほう。よく使うわりにはいつもはまってしまうので備忘録。（&lt;a href="http://cafetalk.com"&gt;カフェトーク&lt;/a&gt;では、レッスンにメモを追加するところにつかってます）
&lt;br /&gt;&lt;br /&gt;
article.rb
&lt;pre class="prettyprint"&gt;
class Article &lt; ActiveRecord::Base
  belongs_to :user
  has_many :comments
  after_update :save_comments
  
  def new_comment_attributes=(comment_attributes)
    comment_attributes.each do |attributes|
      comments.build(attributes) if attributes[:content].length &gt; 0
    end
  end
  
  # ここでは使ってない
  def existing_comment_attributes=(comment_attributes)
    comments.reject(&amp;:new_record?).each do |comment|
      attributes = comment_attributes[comment.id.to_s]
      if attributes
        comment.attributes = attributes
      else
        comments.delete(comment)
      end
    end
  end
  
  def save_comments
    comments.each do |comment|
      comment.save(false)
    end
  end  
  
  # 特定のユーザのみに表示するためのメソッド
  def user_comments
    self.comments.find(:all, :conditions =&gt; {:display_user =&gt; true})
  end
end
&lt;/pre&gt;
&lt;br /&gt;



comment.rb
&lt;pre class="prettyprint"&gt;
class Comment &lt; ActiveRecord::Base
  belongs_to :article 
end
&lt;/pre&gt;


views/articles/show.html.erb
&lt;pre class="prettyprint"&gt;
&lt;div id="comments"&gt;
 &lt;% for comment in @article.pro_comments %&gt;
  &lt;%= render :partial =&gt; 'comment_item', :locals =&gt; {:comment_item =&gt; comment} %&gt;
 &lt;% end %&gt;
&lt;/div&gt;
&lt;%= link_to_function "コメント追加" do |page|
      page.insert_html :bottom, :add_comment, :partial =&gt; 'comment' , :object =&gt; comment.new
end%&gt;
&lt;div id="add_comment"&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;br /&gt;



views/pro/articles/_comment_item.html.erb
&lt;pre class="prettyprint"&gt;
&lt;div class="comment" id="comment_&amp;lt;%= comment_item.id %&amp;gt;"&gt;
 &lt;%= comment_item.content%&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;br /&gt;


views/articles/_comment.html.erb

&lt;pre class="prettyprint"&gt;
&lt;div class="add_comment" &gt;
&lt;% @comment = Comment.new %&gt;
&lt;% form_remote_for ([:comment, @article]), 
  :url =&gt; add_comment_article_path(@article), :html =&gt; { :method =&gt; 'put' } do |f| %&gt;
   &lt;%= f.text_area :content %&gt;
  &lt;%= f.submit "追加"  %&gt;
&lt;% end %&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;br /&gt;

add_comment.rjs
&lt;pre class="prettyprint"&gt;
if params[:comment]
  @comment= comment.new(params[:comment])
  if @comment.save
    comment_item_id = "comment_" + @comment.id.to_s
    page.insert_html :bottom, "comments", :partial =&gt; "comment_item", :object =&gt; @comment
    page[comment_item_id].visual_effect :highlight, :duration =&gt; 0.5, :startcolor =&gt; "#66CCFF"
    page.replace_html "add_comment", ""
  else
    @comment.errors.each{|attr,msg| page.alert("#{attr} - #{msg}")}
  end      
end
&lt;/pre&gt;
&lt;br /&gt;

routes.rb
&lt;pre class="prettyprint"&gt;
map.resources :articles, :member =&gt; {:add_comment =&gt; :put}
&lt;/pre&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-5029963562795836863?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/5029963562795836863/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=5029963562795836863' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/5029963562795836863?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/5029963562795836863?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rjs_09.html' title='Ajax を使ってコメントを挿入'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DU4HQXY6fSp7ImA9WxBQEEw.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-166339902584413377</id><published>2010-01-09T14:54:00.010+09:00</published><updated>2010-01-09T15:18:50.815+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-09T15:18:50.815+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='rjs'/><title>RJS 参考色々</title><content type='html'>最近 rjs を使うことが多くなってきたので、備忘録

&lt;h3&gt;特定のアイテムの下にインサートする場合&lt;/h3&gt;
&lt;pre class="prettyprint"&gt;
page.insert_html :bottom, "item_" + params[:id], :partial =&gt; "item", :object =&gt; item
&lt;/pre&gt;
この場合、partial と object名は一致している必要がある。&lt;br/&gt;
&lt;h3&gt;ハイライト&lt;/h3&gt;
&lt;pre class="prettyprint"&gt;
page[:item].visual_effect :highlight, :duration =&gt; 0.5, :startcolor =&gt; "#66CCFF"
&lt;/pre&gt;
特定のアイテムをハイライトしたい場合(例 div id="item_{アイテムid}")
&lt;pre class="prettyprint"&gt;
item_id = "item_" + item.id.to_s
page[item_id].visual_effect :highlight, :duration =&gt; 0.5
&lt;/pre&gt;
&lt;h3&gt;その他色々&lt;/h3&gt;
&lt;pre class="prettyprint"&gt;
page.alert("hello")

# 表示トグル
page['mytest'].toggle

page.alert(params.inspect)

target_field = "prefix_" + params[:target]
page[target_field].value = temp

page.visual_effect :toggle_appear, params[:somename], :duration =&gt; 0.5
page[:item_form].remove
page.redirect_to root_path
page.replace_html 'someid', :partial =&gt; 'somepartial', :object =&gt; @someobject
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-166339902584413377?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/166339902584413377/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=166339902584413377' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/166339902584413377?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/166339902584413377?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rjs.html' title='RJS 参考色々'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DE4GQnkzeSp7ImA9WxBQFUk.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-4357350446604610805</id><published>2010-01-07T02:20:00.004+09:00</published><updated>2010-01-15T18:15:23.781+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-15T18:15:23.781+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='timezone'/><title>Rails Timezone の設定色々</title><content type='html'>&lt;pre class="prettyprint"&gt;
sometime.in_time_zone("Hawaii")
sometime.in_time_zone(@user.time_zone)
&lt;/pre&gt;



&lt;a href="http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/"&gt;http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://api.rubyonrails.org/classes/TimeZone.html#M000020"&gt;http://api.rubyonrails.org/classes/TimeZone.html#M000020&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://marklunds.com/articles/one/402"&gt;http://marklunds.com/articles/one/402&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html#M001513"&gt;http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html#M001513&lt;/a&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-4357350446604610805?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/4357350446604610805/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=4357350446604610805' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4357350446604610805?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4357350446604610805?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails-timezone.html' title='Rails Timezone の設定色々'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DEMCQXY8eip7ImA9WxBRF0U.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-6728704076419926955</id><published>2010-01-06T01:40:00.002+09:00</published><updated>2010-01-06T23:01:00.872+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-06T23:01:00.872+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='api'/><category scheme='http://www.blogger.com/atom/ns#' term='google'/><title>Cron で実行する</title><content type='html'>プログラムを自動的に実行したいとき。例えば、&lt;a href="http://cafetalk.com"&gt;cafetalk.com&lt;/a&gt; では、レッスンの24時間前にリマインダーメールを送ってます。
&lt;br /&gt;
Linux 系のサーバーで cron を使う場合。（下の例は5分毎に、Mymodelのmymethodを実行)
&lt;pre class="prettyprint"&gt;
*/5 * * * * /usr/bin/ruby /var/www/apps/{project}/script/runner 'Mymodel.mymethod' -e production
&lt;/pre&gt;
&lt;br/&gt;
因みに、Windows で動かす場合。
&lt;pre class="prettyprint"&gt;
ruby script/runner 'Mymodel.mymethod' -e development
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-6728704076419926955?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/6728704076419926955/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=6728704076419926955' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/6728704076419926955?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/6728704076419926955?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/google.html' title='Cron で実行する'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;Ak8ERXY8fip7ImA9WxBRFUQ.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-4171989108855295012</id><published>2010-01-04T18:49:00.002+09:00</published><updated>2010-01-04T18:53:24.876+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T18:53:24.876+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title>Amazon S3 を使ったバックアップなんてどーですか</title><content type='html'>バックアップはかなり苦労が多い。今まで僕がやってたのは定期的にシェルスクリプトを書いて、別のサーバーに転送する方法。

でも、S3 を使えばらくかなー。

↓こちらに方法があるので、いずれチャレンジして報告します。

&lt;a href="http://paulstamatiou.com/how-to-bulletproof-server-backups-with-amazon-s3"&gt;http://paulstamatiou.com/how-to-bulletproof-server-backups-with-amazon-s3&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-4171989108855295012?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/4171989108855295012/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=4171989108855295012' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4171989108855295012?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4171989108855295012?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/amazon-s3.html' title='Amazon S3 を使ったバックアップなんてどーですか'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;CkMDR3s4fyp7ImA9WxBRFk0.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-3471477725652446234</id><published>2010-01-04T17:40:00.009+09:00</published><updated>2010-01-04T19:21:16.537+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T19:21:16.537+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='paperclip'/><title>Paperclip と Amazon S3 でファイルを保存する</title><content type='html'>&lt;a href="http://jzool.com/"&gt;オンラインショップ&lt;/a&gt;のサーバー要領がちょっとキツクなったので、画像データを Amazon S3 を使って保存してみょーと思い立つ。&lt;br /&gt;

ざっくり説明しますと、Amazon S3が外部ストーレージサービス。データをやり取りした分だけ課金されます。1GBで15円ほどなので、安くは無いけど、いろんなメリットを考えると高くもない。とりあえずテストしてみることに決定～。

&lt;h4&gt;まず、Amazon S3 に登録&lt;/h4&gt;


&lt;h4&gt;S3 のデータを見るには『S3Fox』が便利&lt;/h4&gt;
Firefox のプラグイン『&lt;a href="http://www.s3fox.net/"&gt;S3Fox&lt;/a&gt;』を使うと、FTPクライアント風にAmazon S3の中がみれるよ。&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.omniuploader.com/s3fox/features/s3fox_main.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 500px; height: 309px;" src="http://www.omniuploader.com/s3fox/features/s3fox_main.gif" alt="" border="0" /&gt;&lt;/a&gt;


&lt;h4&gt;Paperclip 設定の変更&lt;/h4&gt;
以前、&lt;a href="http://www.blogger.com/2010/01/paperclip.html"&gt;Paperclip の使い方&lt;/a&gt;についてメモりましたが、そこからちょいと手を加えます。

environment.rb に aws gem を追加
&lt;pre class="prettyprint"&gt;
config.gem "aws-s3", :lib =&gt; "aws/s3"
&lt;/pre&gt;
（require する際に require = "aws/s3" とする場合は上のように、 :lib =&gt; "aws/s3"　を加えて記述）


この後、rake gems:install を実行するのを忘れずに。



config/s3.yml を作成
&lt;pre class="prettyprint"&gt;
access_key_id: ABCD...
secret_access_key: xYz...
&lt;/pre&gt;
キーとシークレットはここから。
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8TFao7SH5fc/S0GzLysWayI/AAAAAAAAAOk/krL8V4VT7S0/s1600-h/QS_20100104-181912.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 146px;" src="http://1.bp.blogspot.com/_8TFao7SH5fc/S0GzLysWayI/AAAAAAAAAOk/krL8V4VT7S0/s400/QS_20100104-181912.jpg" alt="" id="BLOGGER_PHOTO_ID_5422812441498512162" border="0" /&gt;&lt;/a&gt;

モデルの変更
&lt;pre class="prettyprint"&gt;
 #通常バージョン
 has_attached_file :image,
   :styles =&gt; {:s =&gt; "150x150&gt;", :m =&gt;"320x320&gt;", :l =&gt; "500x500&gt;"},
   :url  =&gt; "/assets/products/:id/p_:style.:basename.:extension",
   :path =&gt; ":rails_root/public/assets/products/:id/p_:style.:basename.:extension"

 #↓S3 バージョン
 has_attached_file :image,
   :styles =&gt; {:s =&gt; "150x150&gt;", :m =&gt;"320x320&gt;", :l =&gt; "500x500&gt;"},
   :storage =&gt; :s3,
   :s3_credentials =&gt; "#{RAILS_ROOT}/config/s3.yml",
   :path =&gt; "products/:id/:style.:extension",
   :url  =&gt; ":s3_domain_url",
   :bucket =&gt; S3_BUCKET #S3_BUCKET は production/environment.rb development/environment.rb で定義
&lt;/pre&gt;
&lt;br /&gt;
:s3_domain_url だと http://mybucket.s3.amazonaws.com/products/16152/l.jpg のようになる。
&lt;br /&gt;
因みに、上で指定した bucket をあらかじめ作っておく必要があるのですー↓


&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8TFao7SH5fc/S0Gq-CXhPmI/AAAAAAAAAOc/vSVJvtFkNGw/s1600-h/QS_20100104-173718.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 350px;" src="http://1.bp.blogspot.com/_8TFao7SH5fc/S0Gq-CXhPmI/AAAAAAAAAOc/vSVJvtFkNGw/s400/QS_20100104-173718.jpg" alt="" id="BLOGGER_PHOTO_ID_5422803409094917730" border="0" /&gt;&lt;/a&gt;


この場合、S3Fox で作成。



これで準備はOK。さっそくアップロードしてみると。。。


&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8TFao7SH5fc/S0G1BH2hmOI/AAAAAAAAAOs/kQlgm2CpJjk/s1600-h/QS_20100104-182833.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 260px;" src="http://1.bp.blogspot.com/_8TFao7SH5fc/S0G1BH2hmOI/AAAAAAAAAOs/kQlgm2CpJjk/s400/QS_20100104-182833.jpg" alt="" id="BLOGGER_PHOTO_ID_5422814457223026914" border="0" /&gt;&lt;/a&gt;

入ってる！感激～&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-3471477725652446234?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/3471477725652446234/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=3471477725652446234' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/3471477725652446234?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/3471477725652446234?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/paperclip-amazon-s3.html' title='Paperclip と Amazon S3 でファイルを保存する'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_8TFao7SH5fc/S0GzLysWayI/AAAAAAAAAOk/krL8V4VT7S0/s72-c/QS_20100104-181912.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;CEcAQ3Yzfip7ImA9WxBRFUQ.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-1961284726360860008</id><published>2010-01-04T16:57:00.002+09:00</published><updated>2010-01-04T17:00:42.886+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T17:00:42.886+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='command line'/><title>GitHub からプラグインをインストール</title><content type='html'>ウィンドウズの場合、コマンドラインから次を実行

&lt;pre&gt;
ruby script/plugin install git://github.com/thoughtbot/paperclip.git
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-1961284726360860008?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/1961284726360860008/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=1961284726360860008' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1961284726360860008?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1961284726360860008?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/github.html' title='GitHub からプラグインをインストール'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;AkABRXo5eSp7ImA9WxBRFUU.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-1353229255262198366</id><published>2010-01-04T15:35:00.005+09:00</published><updated>2010-01-04T16:05:54.421+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T16:05:54.421+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='paperclip'/><title>Paperclip で画像アップロード</title><content type='html'>ファイルや画像を簡単にアップロードできるプラグイン Paperclip の紹介。
&lt;br /&gt;
&lt;a href="http://github.com/thoughtbot/paperclip/tree/master"&gt;
http://github.com/thoughtbot/paperclip/tree/master&lt;/a&gt;
&lt;br /&gt;
&lt;h4&gt;最初からテーブルに含める場合&lt;/h4&gt;
&lt;pre&gt;
      # migration ファイルに以下を追加
      t.string    :image_file_name, :image_content_type
      t.integer   :image_file_size
      t.datetime  :image_updated_at
      t.string    :image_remote_url
&lt;/pre&gt;
最後の image_remote_url は基本的には必要ないが、URLから画像アップロードしたいので、今回は追加しておく。
&lt;br/&gt;
&lt;h4&gt;既存のテーブルに追加する場合&lt;/h4&gt;
&lt;pre&gt;
class AddImageColumnsToProducts &amp;lt; ActiveRecord::Migration
    def self.up
      add_column :products, :image_file_name,    :string
      add_column :products, :image_content_type, :string
      add_column :products, :image_file_size,    :integer
      add_column :products, :image_updated_at,   :datetime
    end

    def self.down
      remove_column :products, :image_file_name
      remove_column :products, :image_content_type
      remove_column :products, :image_file_size
      remove_column :products, :image_updated_at
    end
end
&lt;/pre&gt;

&lt;h2&gt;モデルの設定&lt;/h2&gt;
&lt;pre class="prettyprint"&gt;
  has_attached_file :image, 
    :styles =&gt; {:s =&gt; "150x150&gt;", :m =&gt;"320x320&gt;", :l =&gt; "500x500&gt;"},
    :url  =&gt; "/assets/products/:id/p_:style.:basename.:extension",
    :path =&gt; ":rails_root/public/assets/products/:id/p_:style.:basename.:extension"  
&lt;/pre&gt;

URLからのアップロードを可能にする場合は次も追加&lt;br /&gt;
&lt;pre class="prettyprint"&gt;

  # ====================================
  # Paper Clip upload from url
  # ====================================
  attr_accessor :image_url    
  before_validation :download_remote_image, :if =&gt; :image_url_provided?
  validates_presence_of :image_remote_url, :if =&gt; :image_url_provided?, :message =&gt; 'is invalid or inaccessible'

  private
 
  def image_url_provided?
    !self.image_url.blank?
  end
 
  def download_remote_image
    self.image = do_download_remote_image
    self.image_remote_url = image_url
  end
 
  def do_download_remote_image
    io = open(URI.parse(image_url))
    def io.original_filename; base_uri.path.split('/').last; end
    io.original_filename.blank? ? nil : io
    rescue # catch url errors with validations instead of exceptions (Errno::ENOENT, OpenURI::HTTPError, etc...)
  end
&lt;/pre&gt;

&lt;pre class="prettyprint"&gt;

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-1353229255262198366?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/1353229255262198366/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=1353229255262198366' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1353229255262198366?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1353229255262198366?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/paperclip.html' title='Paperclip で画像アップロード'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;AkcNSX06eip7ImA9WxBRFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-741901163409109466</id><published>2010-01-04T12:46:00.001+09:00</published><updated>2010-01-04T13:08:18.312+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T13:08:18.312+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='install'/><category scheme='http://www.blogger.com/atom/ns#' term='errors'/><title>Rails 2.2.2 &gt; 2.3.5 uninitialized constant ApplicationController でハマリマス</title><content type='html'>2.2.2 から 2.3.5 にアップグレードしたら、下記のエラー発生。

&lt;pre class="prettyprint"&gt;
uninitialized constant ApplicationController
&lt;/pre&gt;

どうやら、2.3 から、application コントローラーのファイル名が application_controller.rb になったらしいです。ファイル名を変更したらOKになりました。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-741901163409109466?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/741901163409109466/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=741901163409109466' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/741901163409109466?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/741901163409109466?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails-222-235-uninitialized-constant.html' title='Rails 2.2.2 &gt; 2.3.5 uninitialized constant ApplicationController でハマリマス'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;DEQBQXk7eCp7ImA9WxBRFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-6205255413523855672</id><published>2010-01-04T12:21:00.006+09:00</published><updated>2010-01-04T12:39:10.700+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T12:39:10.700+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='install'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='errors'/><category scheme='http://www.blogger.com/atom/ns#' term='gem'/><title>Rails gem 2.2.2 &gt; 2.3.5 アップグレード時にハマリマス</title><content type='html'>&lt;a href="/2010/01/rails-gem.html"&gt;Rails を 2.3.5にフリーズ&lt;/a&gt;した後、さっそくエラー

&lt;pre class="prettyprint"&gt;
`report_activate_error': RubyGem version error: rack(1.0.0 not ~&gt; 1.0.1) Gem::LoadError)
&lt;/pre&gt;
なるほど、rack が必要そうなので、gem をインストール
&lt;pre class="prettyprint"&gt;
gem install rack
Successfully installed rack-1.1.0
1 gem installed
&lt;/pre&gt;
これでも動かない。そりゃ、そうでですね。よく見たら必要なバージョンは 1.0.1。気を取り直して、バージョン指定で。
&lt;pre class="prettyprint"&gt;
gem install rack --version 1.0.1 --no-rdoc --no-ri
Successfully installed rack-1.0.1
1 gem installed
&lt;/pre&gt;
これでOK。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-6205255413523855672?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/6205255413523855672/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=6205255413523855672' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/6205255413523855672?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/6205255413523855672?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails-gem-222-235.html' title='Rails gem 2.2.2 &gt; 2.3.5 アップグレード時にハマリマス'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;D0YAQn47fSp7ImA9WxBRFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-7254449765293923660</id><published>2010-01-04T12:04:00.004+09:00</published><updated>2010-01-04T12:19:03.005+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T12:19:03.005+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='gems'/><title>特定のバージョンで rails の gem をフリーズする</title><content type='html'>特定のバージョンでフリーズしたいこともあるなり。

&lt;pre class="prettyprint"&gt;
rake VERSION=2.3.5 rails:freeze:gems
&lt;/pre&gt;

config/environments.rb の編集も忘れずに
&lt;pre class="prettyprint"&gt;
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-7254449765293923660?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/7254449765293923660/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=7254449765293923660' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7254449765293923660?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/7254449765293923660?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails-gem.html' title='特定のバージョンで rails の gem をフリーズする'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;A0YFQno4fCp7ImA9WxBRFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-1347776525354679475</id><published>2010-01-04T12:01:00.007+09:00</published><updated>2010-01-04T13:25:13.434+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T13:25:13.434+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='i18n'/><category scheme='http://www.blogger.com/atom/ns#' term='routes'/><title>Rails 言語をパスで管理する方法</title><content type='html'>http://waraukigoya.com/&lt;b&gt;ja&lt;/b&gt;/mypage のように、URLパスの一部を使って言語管理する方法があります。

&lt;a href="http://gist.github.com/25476"&gt;パッチ&lt;/a&gt;があったので適用。

&lt;pre class="prettyprint"&gt;
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index ff44849..f3a4f09 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -170,18 +170,24 @@ module ActionController
               def #{selector}(*args)
                 #{generate_optimisation_block(route, kind)}
 
+                locale = #{route.segment_keys.include?(:locale) ? '{ :locale =&gt; I18n.locale || I18n.default_locale }' : '{}'}
+
                 opts = if args.empty? || Hash === args.first
                   args.first || {}
                 else
                   options = args.extract_options!
-                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|
+
+                  segments = #{route.segment_keys.inspect}
+                  #{'segments.delete(:locale) if segments.size &gt; args.size' if route.segment_keys.include?(:locale)}
+
+                  args = args.zip(segments).inject({}) do |h, (v, k)|
                     h[k] = v
                     h
                   end
                   options.merge(args)
                 end
 
-                url_for(#{hash_access_method}(opts))
+                url_for(#{hash_access_method}(locale.merge(opts)))
               end
               protected :#{selector}
             end_eval
&lt;/pre&gt;

次に routes.rb ファイルを設定する必要あり。

&lt;pre class="prettyprint"&gt;
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
  
  # ====================================================
  # Put all non locale controlled routes above this line
  # 通常ルートの下に、path_prefix で管理したルートを設定
  # ====================================================
  
  map.resources :mypages, :path_prefix =&gt; "/:locale"
  map.root :controller =&gt; "mypages", :action =&gt; "index", :locale =&gt; "ja"
  
  map.connect '/:locale/:controller/:action/:id'
  map.connect '/:locale/:controller/:action/:id.:format'
&lt;/pre&gt;
これをやっておけば、リンクヘルパーを使った際、自動的に現在の locale が引き継がれるので便利。

&lt;pre class="prettyprint"&gt;
例えば、http://mysite.com/ja/home

の中で、&lt;%= link_to "記事", mypages_path %&gt; と書くと、次のようになる

&amp;lt;a href="http://mysite.com/ja/mypages"&amp;gt;記事
&lt;/pre&gt;
もちろん、アプリケーションコントローラーで言語の設定は必要。

&lt;pre class="prettyprint"&gt;

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-1347776525354679475?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/1347776525354679475/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=1347776525354679475' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1347776525354679475?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/1347776525354679475?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/rails.html' title='Rails 言語をパスで管理する方法'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry gd:etag='W/&quot;CkIDRH07fyp7ImA9WxBRFUo.&quot;'><id>tag:blogger.com,1999:blog-9060534060342359070.post-4363769141626967667</id><published>2010-01-04T10:35:00.003+09:00</published><updated>2010-01-04T11:02:55.307+09:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-01-04T11:02:55.307+09:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='blogger'/><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title>Blogger でソースコードを綺麗に embed する方法</title><content type='html'>開発系の備忘録をブログにアップしようと思ったけど、ブロガーだとソースコードが綺麗に表示されない。なので、google のライブラリ Prettify を使ってみた。

&lt;pre class="prettyprint"&gt;
def generate_request_status_select(f)
return f.select( :request_status, [
[ _("Waiting for Quote"), 1],
[ _("Waiting for Customer Decision"), 2],
[ _("Incomplete Order"), 3]
])
end
&lt;/pre&gt;

参考：
&lt;a href="http://philipmjohnson.blogspot.com/2009/09/test-of-pretty-print.html"&gt;PMJ Engineering's article on using prettify to paste pretty code onto Blogger.&lt;/a&gt;


&lt;a href="http://104tech.blogspot.com/2007/04/blogger.html"&gt;こちらも。&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9060534060342359070-4363769141626967667?l=noviceonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://noviceonrails.blogspot.com/feeds/4363769141626967667/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=9060534060342359070&amp;postID=4363769141626967667' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4363769141626967667?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9060534060342359070/posts/default/4363769141626967667?v=2'/><link rel='alternate' type='text/html' href='http://noviceonrails.blogspot.com/2010/01/def-generaterequeststatusselectf-return.html' title='Blogger でソースコードを綺麗に embed する方法'/><author><name>matto</name><uri>http://www.blogger.com/profile/14134514378913425197</uri><email>noreply@blogger.com</email><gd:extendedProperty name='OpenSocialUserId' value='07690907656747425586'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>