2010-01-01から1年間の記事一覧

rails入力チェックの独自実装

rails3でvalidatorを実装した場合に lib/hoge_validator.rbをおいただけだとモデルで validates, :foo, :hoge => true でそんなバリデーションないヽ(`Д´)ノプンプンって怒られる rails3からは自動で読み込まないとのことで require 'lib/hoge_validator.rb' を…

railsでメッセージを日本語化するときにネストした項目を日本語する方法

AテーブルにひもづくBテーブルを一度に更新する場合にAのエラーもBのエラーも出したいconfig/locales/ja.yml (どっかからパクったのに追加) activerecord: models: user: ユーザー item: アイテム attributes: user: name: 名前 sex: 性別 age: 年齢 item: n…

deviseでモジュールを追加する方法

change_tableでmigrationを記述 class AddUsersLockable < ActiveRecord::Migration def self.up change_table(:users) do |t| t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both end add_index :users, :unlock_token, :unique =>…