將重定向推送到錯誤消息的最佳方式是什麼?通過閃存傳遞錯誤消息
我以前使用過幾種方法,但他們都有問題。
(1)與誤差傳遞整個對象上閃光並使用error_messages_for:
def destroy
if @item.destroy
flash[:error_item] = @item
end
redirect_to some_other_controller_path
end
我發現,此方法會導致餅乾溢出。
(2)傳遞一個錯誤信息:
def destroy
if @item.destroy
flash[:error] = @item.full_messages[0]
end
redirect_to some_other_controller_path
end
這樣,我只發送一個錯誤信息,如果有很多? 有沒有人知道更好的方法?
絕對好用!謝謝! – alexs333
對於您示例的'其他'部分,您應該使用 'flash.now [:error] =「Action failed」 請參閱:[the-flash](http://guides.rubyonrails.org/action_controller_overview .html#the-flash) – Joris