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

<channel>
	<title>ゆーすけぶろぐ &#187; rails</title>
	<atom:link href="http://yusukezzz.net/blog/archives/tag/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://yusukezzz.net/blog</link>
	<description>yusukezzz&#039;s weblog... ぷろぐらむとか ruby, android, java, thinkpad, milestone2</description>
	<lastBuildDate>Sat, 10 Mar 2012 17:22:54 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ActiveSupportで日時変換</title>
		<link>http://yusukezzz.net/blog/archives/1526</link>
		<comments>http://yusukezzz.net/blog/archives/1526#comments</comments>
		<pubDate>Wed, 02 Sep 2009 07:22:16 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1526</guid>
		<description><![CDATA[Railsではたまに1.week.from_nowといった書き方を見ます これはActiveSupportによってnumericクラスが拡張されているもので、様々な指定方法があります 例えば、？時からその日中(23:59 [...]]]></description>
			<content:encoded><![CDATA[<p>Railsではたまに1.week.from_nowといった書き方を見ます<br />
これはActiveSupportによってnumericクラスが拡張されているもので、様々な指定方法があります</p>
<p>例えば、？時からその日中(23:59まで)のデータをfindしたい場合、</p>
<pre class="brush: ruby; title: ; notranslate">
# 12:00～23:59まで
date = Time.parse(&quot;12:00&quot;)
cond = []
cond &lt;&lt; &quot;created_at &gt; ? AND created_at &lt; ?&quot;
cond &lt;&lt; date
cond &lt;&lt; (date + 1.day).beginning_of_day
@data = Model.find(:all, :conditions =&gt; cond)
</pre>
<p>といった書き方が出来ます<br />
beginning_of_dayは時間の部分をその日の00:00に変換したtimeオブジェクトを返します（Time型のみ）</p>
<p><a href="http://d.hatena.ne.jp/spitfire_tree/20080223/1203760297" target="_blank">Rails の Date, Time 拡張</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1526/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controllerから呼ばれるHelperで</title>
		<link>http://yusukezzz.net/blog/archives/1523</link>
		<comments>http://yusukezzz.net/blog/archives/1523#comments</comments>
		<pubDate>Sat, 22 Aug 2009 14:10:45 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1523</guid>
		<description><![CDATA[今日の作業で良くわかんなかったとこ AjaxリクエストへHTML（tableのセル）を返す処理で、以前はControllerに書いていた処理をHelperに移してみた その際、折角だからViewでも一部被ってた部分をマー [...]]]></description>
			<content:encoded><![CDATA[<p>今日の作業で良くわかんなかったとこ</p>
<p>AjaxリクエストへHTML（tableのセル）を返す処理で、以前はControllerに書いていた処理をHelperに移してみた<br />
その際、折角だからViewでも一部被ってた部分をマージしてlink_toやimage_tagなどのHelperメソッドに置き換えた<br />
（ViewでもそのHTMLが欲しい時にHelperを呼ぶようにするため）<br />
すると、Viewからは普通に呼べるのだけど、AjaxでControllerからHelperを呼ぶとlink_toやimage_tagがうまく動かなかった<br />
色々includeとかしてみたけどlink_toで必ずnil.url_forとなってしまったので諦めた（結局HTMLべた書きした）</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1523/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Railsのform_forでの注意</title>
		<link>http://yusukezzz.net/blog/archives/1494</link>
		<comments>http://yusukezzz.net/blog/archives/1494#comments</comments>
		<pubDate>Tue, 04 Aug 2009 09:56:38 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1494</guid>
		<description><![CDATA[のような書き方をするとうまく保存されません WARNING: Can&#8217;t mass-assign these protected attributes: id のような警告をlogに吐きます どうやらidは上 [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: ruby; title: ; notranslate">
# view
&lt;% form_for :hoge, :url =&gt; {:action =&gt; :update} do |f| %&gt;
  &lt;% f.hidden_field :id, {:value =&gt; @hoge.id} %&gt;
  &lt;% f.text_field :name, {:value =&gt; @hoge.name} %&gt;
  &lt;% f.submit %&gt;
&lt;% end %&gt;
</pre>
<pre class="brush: ruby; title: ; notranslate">
# controller
def update
  if params[:hoge]
    hoge = Hoge.find_by_id(params[:hoge][:id])
    hoge.attributes = params[:hoge]
    hoge.save!
  end
end
</pre>
<p>のような書き方をするとうまく保存されません<br />
WARNING: Can&#8217;t mass-assign these protected attributes: id<br />
のような警告をlogに吐きます<br />
どうやらidは上書きも認められてないようです<br />
hidden_fieldではなく、form_forの引数として渡すとうまく行きます</p>
<pre class="brush: ruby; title: ; notranslate">
# view
&lt;% form_for :hoge, :url =&gt; {:action =&gt; :update, :id =&gt; @hoge.id} do |f| %&gt;
  &lt;% # f.hidden_field :id, {:value =&gt; @hoge.id} %&gt;
  &lt;% f.text_field :name, {:value =&gt; @hoge.name} %&gt;
  &lt;% f.submit %&gt;
&lt;% end %&gt;
</pre>
<pre class="brush: ruby; title: ; notranslate">
# controller
def update
  if params[:hoge]
    # hoge = Hoge.find_by_id(params[:hoge][:id])
    hoge = Hoge.find_by_id(params[:id])
    hoge.attributes = params[:hoge]
    hoge.save!
  end
end
</pre>
<p>これでうまいこと更新出来ます</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1494/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Railsのcheck_box_tag</title>
		<link>http://yusukezzz.net/blog/archives/1493</link>
		<comments>http://yusukezzz.net/blog/archives/1493#comments</comments>
		<pubDate>Mon, 03 Aug 2009 08:21:48 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1493</guid>
		<description><![CDATA[だとチェックしてもうまく行かない（hoge[check]がtrueになってない） しっかりvalueを設定する必要がある valueがtrueだとちゃんとチェックボックスの値を受け取れるみたい 3つ目の引数はchecke [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: ruby; title: ; notranslate">
&lt;%= check_box_tag &quot;hoge[check]&quot; %&gt;
</pre>
<p>だとチェックしてもうまく行かない（hoge[check]がtrueになってない）<br />
しっかりvalueを設定する必要がある</p>
<pre class="brush: ruby; title: ; notranslate">
&lt;%= check_box_tag &quot;hoge[check]&quot;, 1, false %&gt;
&lt;%= check_box_tag &quot;hoge[check]&quot;, true %&gt;
</pre>
<p>valueがtrueだとちゃんとチェックボックスの値を受け取れるみたい<br />
3つ目の引数はcheckedに当たります</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1493/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Railsでiphoneからのアクセスを振り分け</title>
		<link>http://yusukezzz.net/blog/archives/1484</link>
		<comments>http://yusukezzz.net/blog/archives/1484#comments</comments>
		<pubDate>Fri, 31 Jul 2009 08:25:59 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1484</guid>
		<description><![CDATA[Rails2.3.3で確認 [追記1] set_iphone_formatにviewファイルを振り分ける記述を追記 [追記2]振り分けれてなかったので修正… こんな感じにしとくと、iphoneからのアクセスでは view [...]]]></description>
			<content:encoded><![CDATA[<p>Rails2.3.3で確認<br />
[追記1] set_iphone_formatにviewファイルを振り分ける記述を追記<br />
[追記2]振り分けれてなかったので修正…</p>
<pre class="brush: ruby; title: ; notranslate">
# config/initializers/mime_types.rb
# 以下の行のコメントを外す
Mime::Type.register_alias &quot;text/html&quot;, :iphone

###
# application_controller.rb
  # iphone/ipod touchからのアクセスかどうか（ちょっと適当っぽい）
  def is_iphone_request?
    request.user_agent =~ /(Mobile\/.+Safari)/
  end

  # iphone/ipod touchだったらiphone向けに表示切換え
  def set_iphone_format
    if is_iphone_request?
      request.format = :iphone
    end
  end

###
# hoge_controller
  def index
    ...
    respond_to do |format|
      format.html
      format.iphone
    end
  end
</pre>
<p>こんな感じにしとくと、iphoneからのアクセスでは<br />
views/layout/application.iphone.html.erb<br />
views/hoges/index.iphone.html.erb<br />
を描画してくれます</p>
<p>＃iphone用のディレクトリを用意してそこに*.iphone.html.erbを全部ぶっ込んで使うにはどうすればいいんだろう…<br />
＃iphone用コントローラとか作りたくないし；</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1484/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Rails]HelperのメソッドをControllerで使う</title>
		<link>http://yusukezzz.net/blog/archives/1482</link>
		<comments>http://yusukezzz.net/blog/archives/1482#comments</comments>
		<pubDate>Thu, 30 Jul 2009 07:51:51 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1482</guid>
		<description><![CDATA[でHugaHelperのメソッドが（ついでにViewでも）使えるようになります helper :huga との違いはControllerでも使えるようになる点です （helperで呼ぶとViewだけで使えるようになる）]]></description>
			<content:encoded><![CDATA[<pre class="brush: ruby; title: ; notranslate">
class HogeController &lt;&lt; ApplicationController
  include HugaHelper
  ...
end
</pre>
<p>でHugaHelperのメソッドが（ついでにViewでも）使えるようになります</p>
<p>helper :huga<br />
との違いはControllerでも使えるようになる点です<br />
（helperで呼ぶとViewだけで使えるようになる）</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1482/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails更新後に500 internal server error &#124; undefined method `rewind&#8217;</title>
		<link>http://yusukezzz.net/blog/archives/1470</link>
		<comments>http://yusukezzz.net/blog/archives/1470#comments</comments>
		<pubDate>Thu, 23 Jul 2009 14:41:01 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1470</guid>
		<description><![CDATA[Passenger2.1.2でRailsを2.3.3にしてアクセスしたらこんなエラーが出てました 画面上の出力は500エラーだけでログに書いてあったのがundefined method `rewind&#8217;という [...]]]></description>
			<content:encoded><![CDATA[<p>Passenger2.1.2でRailsを2.3.3にしてアクセスしたらこんなエラーが出てました<br />
画面上の出力は500エラーだけでログに書いてあったのがundefined method `rewind&#8217;というエラー<br />
これはRackが吐いてるエラーで、どうやらPassengerの古いverを使ってると遭遇するようです</p>
<p><a href="http://groups.google.com/group/emm-ruby/browse_thread/thread/9e3444275e326bcf?pli=1" target="_blank">undefined method `rewind&#8217;</a></p>
<p>ようはPassengerを最新にすればいいだけです</p>
<pre class="brush: plain; title: ; notranslate">
sudo gem install passenger
sudo passenger-install-apache2-module
</pre>
<p>そしてhttpd.confを修正してapache2を再起動したら直りました<br />
＃何故かsudo gem update passengerでは駄目でした；</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1470/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cache周りの設定</title>
		<link>http://yusukezzz.net/blog/archives/1467</link>
		<comments>http://yusukezzz.net/blog/archives/1467#comments</comments>
		<pubDate>Thu, 23 Jul 2009 06:48:23 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1467</guid>
		<description><![CDATA[Rails2.3.3のキャッシュ周りのお話 environments/development.rbなんかに記述します verごとに微妙に仕様が変わっててげんなりしました…orz 今後確実にキャッシュは使っていくはずなので [...]]]></description>
			<content:encoded><![CDATA[<p>Rails2.3.3のキャッシュ周りのお話<br />
environments/development.rbなんかに記述します</p>
<pre class="brush: ruby; title: ; notranslate">
# キャッシュを有効に
config.action_controller.perform_caching = true

# フラグメントキャッシュの保存先
# 最新のverではこういう指定方法になったそうです…数時間はまってました；
config.action_controller.cache_store = :file_store, &quot;#{RAILS_ROOT}/tmp/cache&quot;

# ページキャッシュの保存先
# ここを変えただけだとpageキャッシュが無効になります（mod_rewriteで変更先にキャッシュを読みに行くよう設定する必要があります）
# config.action_controller.page_cache_directory = &quot;#{RAILS_ROOT}/tmp/cache/page&quot;
</pre>
<p>verごとに微妙に仕様が変わっててげんなりしました…orz<br />
今後確実にキャッシュは使っていくはずなのでしっかり覚えておきたいですね<br />
キャッシュの詳しい使い方はまた今度まとめようと思います</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1467/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails2.3にupgradeしたらまずやること</title>
		<link>http://yusukezzz.net/blog/archives/1460</link>
		<comments>http://yusukezzz.net/blog/archives/1460#comments</comments>
		<pubDate>Thu, 23 Jul 2009 02:42:05 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/?p=1460</guid>
		<description><![CDATA[RAILS_GEM_VERSIONを弄るのもそうでしょうが、 /app/controller/application.rbがapplication_controller.rbにファイル名が変わっているので注意が必要です  [...]]]></description>
			<content:encoded><![CDATA[<p>RAILS_GEM_VERSIONを弄るのもそうでしょうが、<br />
/app/controller/application.rbがapplication_controller.rbにファイル名が変わっているので注意が必要です<br />
これは手動で書きかえなければなりません（rakeでアップグレードすることも出来るらしいですが未確認）<br />
何故かproductionだと問題なく動くのでdevelopmentに戻してからしばらくはまってました；</p>
<p>RailsではコントローラはXXX_controller.rbというファイル名が標準なのに、application.rbだけそれに則っていないというのが問題だったみたいです<br />
とりあえず旧形式でも動くようにして欲しかったと思いますが…</p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1460/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>expire_fragmentをcontrollerに限らずどこでも使うには？</title>
		<link>http://yusukezzz.net/blog/archives/1461</link>
		<comments>http://yusukezzz.net/blog/archives/1461#comments</comments>
		<pubDate>Thu, 23 Jul 2009 02:41:49 +0000</pubDate>
		<dc:creator>yusukezzz</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://yusukezzz.net/blog/archives/1461</guid>
		<description><![CDATA[フラグメントキャッシュを削除するためのメソッドです 普通はSweeperControllerを用意してModelの操作時に消す処理を書くらしいです のような形で呼べばmodelだろうがscriptだろうがどこでも使えるよ [...]]]></description>
			<content:encoded><![CDATA[<p>フラグメントキャッシュを削除するためのメソッドです<br />
普通はSweeperControllerを用意してModelの操作時に消す処理を書くらしいです</p>
<pre class="brush: ruby; title: ; notranslate">
ActionController::Base.new.expire_fragment(key, :options =&gt; nil)
</pre>
<p>のような形で呼べばmodelだろうがscriptだろうがどこでも使えるようです<br />
今回はscriptで使う必要が出たので調べてみました</p>
<p><a href="http://stackoverflow.com/questions/393395/how-to-call-expirefragment-from-rails-observer-model">How to call expire_fragment from Rails Observer/Model? &#8211; Stack Overflow</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yusukezzz.net/blog/archives/1461/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

