2013-03-24から1日間の記事一覧

controllerにバリデーションを書く

Rails3 if target_date.current_date_over? @timemachine.errors.add(:date, "を明日以降の日付で作成することはできません。" render :new end

非アクティブモデルのモデルを日本語化

Rails3ActiveRecordのモデルは、lang.ymlに以下の階層で書けば読み込まれる。 ja: activerecord: models: user: ユーザー report: 報告 attributes: report: property_hour: 資産 ActiveModelだと以下のようにすればよい。 ja: activerecord: models: user: …

Railsでクラス拡張

どこにおくのがベストなんやろと調べた。以下のコードをアプリケーションが読み込むタイミングあたりに仕込む。applicatipn.rbの中がベストなのだろうか。 Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each {|l| require l } # lib/core_ext/str…