gem Respondersを使用していますが、 を使用してモデルで作成したエラーを表示できませんerros.add(:base, 'Error message')
。
私のコントローラーで、の前に、オブジェクトrespond_with @app
をデバッグしましたが、エラーが返されました@app
@app.errors.any?
true
私の見解では、オブジェクトflash
と@app
オブジェクトをチェックすると、エラーはありません
アプリ コントローラー
# app_controllers.rb
def destroy
@app = current_company.apps.find(params[:id])
@app.destroy
respond_with @app
end
アプリのモデル
# app.rb
before_destroy :destroy_on_riak
# ...
def destroy_on_riak
# SOME CODE HERE
rescue Exception => e
errors.add(:base, I18n.t("models.app.could_not_destroy", :message => e.message))
return false
end
アプリ ビュー
# apps.html.haml
-flash.each do |name, msg|
%div{:class => "flash #{name}"}
=content_tag :p, msg if msg.is_a?(String)
これは、@app.destroy
"#<ActiveModel::Errors:0x00000004fa0510 @base=#<App id: 34, ...>, @messages={}>"
これは@app オブジェクトです。@app.destroy
"#<ActiveModel::Errors:0x00000004fa0510 @base=#<App id: 34, ...>, @messages={:base=>[\"Não foi possível excluir a aplicação: undefined method `get_or_new' for #<App:0x00000004f824c0>\"]}>"
@base=
簡単にするために、内部にあるものを削除しました。