我对在rails中使用flash和notice有一点困惑
下面两段代码的区别是什么?
format.html { redirect_to root_path, notice: 'success message' }和
flash[:success]推荐的方法是什么?
发布于 2014-06-25 02:27:23
哈希表中最简单的形式就是flash。你可以这样理解:success和:notice:
flash = { notice: 'watch out', success: 'you dodged it' }你甚至可以注册你自己的类型:
class ApplicationController
add_flash_types :custom
end之所以有不同的类型,主要是为了前端格式化。您可以循环浏览flash消息,并根据flash类型添加不同的样式。警告可能是黄色,成功可能是绿色,错误可能是红色,等等。
https://stackoverflow.com/questions/24393621
复制相似问题