Java   Commons   Rails   IT用語   ネタ系  

2009年07月13日

【1日1Rails】script/generate その4

script/generate integration_test

続きを読む
posted by MW at 01:13| Comment(0) | TrackBack(0) | Rails

2009年07月12日

【1日1Rails】script/generate その3

script/generate helper

続きを読む
posted by MW at 01:55| Comment(0) | TrackBack(0) | Rails

2009年07月11日

【1日1Rails】script/generate その2

コントローラの自動生成
script/generate controller [action]


続きを読む
posted by MW at 01:40| Comment(0) | TrackBack(0) | Rails

2009年07月09日

【1日1Rails】小数点第何位で丸める

Ruby 1.8.7
Rails 2.3.2
小数点第何位かを指定して丸める


続きを読む
posted by MW at 01:16| Comment(0) | TrackBack(0) | Rails

2009年07月07日

【1日1Rails】script/destroy

Ruby 1.8.7
Rails 2.3.2
script/destroyについて


続きを読む
posted by MW at 23:44| Comment(0) | TrackBack(0) | Rails

【1日1Rails】script/dbconsole

Ruby 1.8.7
Rails 2.3.2
script/dbconsoleについて

続きを読む
posted by MW at 01:00| Comment(0) | TrackBack(0) | Rails

2009年07月06日

【1日1Rails】script/console

Ruby 1.8.7
Rails 2.3.2
script/consoleについて


続きを読む
posted by MW at 01:12| Comment(0) | TrackBack(0) | Rails

2009年07月05日

【1日1Rails】script/about

Ruby 1.8.7
Rails 2.3.2
script/aboutの実行結果例


続きを読む
posted by MW at 03:11| Comment(0) | TrackBack(0) | Rails

2009年07月04日

【1日1Rails】scriptディレクトリのコマンド説明

Ruby 1.8.7
Rails 2.3.2
スクリプトディレクトリのコマンドの機能、用途等


続きを読む
posted by MW at 00:39| Comment(0) | TrackBack(0) | Rails

2009年07月02日

【1日1Rails】YAML形式への変換、デコード

Ruby 1.8.7
Rails 2.3.2
YAMLへの変換、デコード
to_yaml
YAML.load


続きを読む
posted by MW at 22:22| Comment(0) | TrackBack(0) | Rails

2009年07月01日

【1日1Rails】JSONへの変換、デコード

Ruby 1.8.7
Rails 2.3.2
JSONへの変換、デコード
to_json
ActiveSupport::JSON.decode


続きを読む
posted by MW at 00:22| Comment(0) | TrackBack(0) | Rails

2009年06月30日

【1日1Rails】単数形、複数形の変換

Ruby 1.8.7
Rails 2.3.2
英単語の単数形 <=> 複数形変換
命名を大事にするRailsにとってはとても大事な機能

pluralize, singularize


続きを読む
posted by MW at 01:03| Comment(0) | TrackBack(0) | Rails

2009年06月28日

【1日1Rails】前月・翌月を取得する

Ruby 1.8.7
Rails 2.3.2

# Dateでやってますが、Timeでも動きます

# 先月=last_month, 翌月=next_month
>> date = Date.new(2009, 1, 1)
  => Thu, 01 Jan 2009
>> date.last_month
  => Mon, 01 Dec 2008
>> date.next_month
  => Sun, 01 Feb 2009

# 2ヶ月後、2ヶ月前
>> date.months_ago(2)
  => Sat, 01 Nov 2008
>> date.months_since(2)
  => Sun, 01 Mar 2009

# monthをyearにすれば、年の扱い
>> date.next_year
  => Fri, 01 Jan 2010
>> date.last_year
  => Tue, 01 Jan 2008
>> date.years_ago(2)
  => Mon, 01 Jan 2007
>> date.years_since(2)
  => Sat, 01 Jan 2011

# 標準関数でやるとこんな感じ
>> date = Date.new(2009, 1, 1)
>> date << 1
  => 20081201

# ちなみに3月31日の1ヶ月前2月28日
>> date = Date.new(2009, 3, 31)
>> date << 1
  => 20090228
posted by MW at 19:28| Comment(0) | TrackBack(0) | Rails

2009年06月27日

【1日1Rails】月の末日を取得する

Ruby 1.8.7
Rails 2.3.2

# end_of_monthで取れる
Date.today.end_of_month #=> Tue 30 Jun 2009

# Timeだと末日の最終秒が取れる
Time.now.end_of_month #=> Tue Jun 30 23:59:59 +0900 2009

# Rubyの標準関数のみでやろうとすると、こんな感じ
Date.new( Date.today.year, Date.today.month, -1 ) #=> Tue 30 Jun 2009
posted by MW at 22:34| Comment(0) | TrackBack(0) | Rails

【1日1Rails】SQLを直接実行する

# Railsで直接SQLを発行する
# エンコード指定を打ちたい時、
# ActiveRecordの実行速度がボトルネックになる時などに使用
 
# SELECTも実行できる
rs = ActiveRecord::Base.connection.execute( "select * from hoge" )
rs.each { | item |
  puts item[0]
}
posted by MW at 02:06| Comment(0) | TrackBack(0) | Rails