Railsでいうところの@user.error
エラー情報を追加するためには、以下のようにします。
1 @user.errors.add(:login, "login is invalid") 2 @user.errors.add(:general, "I'm in a bad mood today :-P"
errorsは、
DataMapper
Railsでいうところの@user.error
エラー情報を追加するためには、以下のようにします。
1 @user.errors.add(:login, "login is invalid") 2 @user.errors.add(:general, "I'm in a bad mood today :-P"
errorsは、
DataMapper
merb-auth-
merb-auth-
1 # Initialization hook - runs before AfterAppLo ads BootLoader 2 def self.init 3 # Actually check if the user is active 4 ::Merb::Authentica tion.after_auth entication do |user, *rest| 5 if user.respond_to ?(:active?) 6 user.active? ? user : nil 7 else 8 user 9 end 10 end 11 end
ただ、この実装では、ログインに失敗した場合に何のエラーメッセージも表示されないため、以下のようにExceptions
1 class Exceptions< Merb::Cont roller 2 (snip) 3 def unauthenti cated 4 request.exceptions .each do |e| 5 session.authentica tion.errors.add(:general, e.message) 6 end if request.exceptions 7 render :format => :html 8 end 9 end
Merbでは、アクションの実行中に例外が発生した場合、Exceptionsrequest.ex
で参照出来ます。
あとは、view側で
1 <%= error_messages_for session.authentica tion %>
を記述すればOK.
merbにはautomigrat
merbの場合、以下のようなコマンドでマイグレーションファイルを作成します。
1 % merb-gen migration name_of_migration
schema/mig
という感じでマイグレーションファイルが生成されます。中身はこんな感じ。
1 migration 1, :name_of_migration do 2 up do 3 end 4 5 down do 6 end 7 end
See Also
幸か不幸かいままで気がつかなかったのですが、
sqlite3ではDROP COLUMNが使えないらしい。
do_sqlite3
sqlite3はiPhoneアプリでも使ってるので、カラムの削除はなるべくしなくてすむように気をつけよう。
See Also