ActionDispatch::Flash < Objec

pass temporary primitive-types (String, ArrayHash) between actions.

Anything you place in the flash will be exposed to the very next action and then cleared out.

用于增加通知,警告信息,例子:

def create
flash[:notice] = "Post successfully created"
redirect_to @post
end
 

模块ActionController::Flash里面有一个实例私有方法:

redirect_to(options = {}, response_status_and_flash = {})可以把flash信息做参数返回到下一个action.

例子:redirect_to(store_index_path, notice: "...")

ActionDispatch::Flash::FlashHash < Object 有20多个方法:

如alert, notice, 可以用chain方式写法:flash.notice = "..."

keep(k = nil):

Keeps either the entire current flash or a specific flash entry available for the next action:

flash.keep # keeps the entire flash 
flash.keep(:notice) # keeps only the "notice" entry, 
the rest of the flash is discarded

now() :只能用于在当前动作下使用

Sets a flash that will not be available to the next action, only to the current.

flash.now[:message] = "Hello current action"


ModuleActiveSupport::Rescuable::ClassMethods

用在对类的错误的营救:

rescue_from(*klasses, with: nil, &block)

Rescue exceptions raised in controller actions.

参数1:a series of exception classes or class names,

参数2: and a trailing :with option with the name of a method or a Proc object to be called to handle them. Alternatively a block can be given.

class ApplicationController < ActionController::Base
rescue_from User::NotAuthorized, with: :deny_access # self defined exception
rescue_from ActiveRecord::RecordInvalid, with: :show_errors
rescue_from 'MyAppError::Base' do |exception|
render xml: exception, status: 500
end
private
def deny_access
...
end
def show_errors(exception)
exception.record.new_record? ? ...
end
end

Rails 使用 ActiveSupport::Logger 类把信息写入日志。

在log文件内隐藏着development.log, test.log.

guide指导:http://guides.rubyonrails.org/debugging_rails_applications.html#the-logger

每一个控制器都有logger属性,可以在其中的action中增加logger.XXX()方法。

 logger.debug "New article: #{@article.attributes.inspect}"

Sending Messages

To write in the current log use the logger.(debug|info|warn|error|fatal) from within a controller, model or mailer。控制器,模块,邮件模块,都可以添加logger.xxx()方法。

3-30 flash(api),rescue_from(); logger简介的更多相关文章

  1. 没有任何秘密的 API:Vulkan* 简介

    Vulkan 被视作是 OpenGL 的后续产品. 它是一种多平台 API,可支持开发人员准备游戏.CAD 工具.性能基准测试等高性能图形应用. 它可在不同的操作系统(比如 Windows*.Linu ...

  2. KnockoutJS 3.X API 第一章 简介

    本文纯正翻译自官网API文档.其中包含一下个人理解. 官网API地址:http://knockoutjs.com/documentation/introduction.html 简介 Knockout ...

  3. 0601-Zuul构建API Gateway-API gateway简介、基础使用、路由配置、负载配置

    一.API Gateway简介 参看:http://www.cnblogs.com/bjlhx/p/8794437.html 二.zuul简介[路由器和过滤器:Zuul] 在微服务架构的组成部分进行路 ...

  4. ASP.NET Core 3.0 WebApi中使用Swagger生成API文档简介

    参考地址,官网:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view ...

  5. Android开发-API指南-Android简介

    Introduction to Android 英文原文:http://developer.android.com/intl/zh-cn/guide/index.html 采集日期:2014-4-16 ...

  6. JDK Logger 简介 (zhuan)

    http://antlove.iteye.com/blog/1924832 ******************************************* 一 简述 java.util.log ...

  7. 22 | 从0到1:API测试怎么做?常用API测试工具简介

  8. Java的常用API之包装类简介

    包装类 包装类: 基本数据类型,使用起来非常方便,但是没有对应的方法来操作这些基本类型的数据可以使用一个类,把基本类型的数据装起来,在类中定义一些方法,这个类叫做包装类,我们可以使用类中的方法来操作这 ...

  9. Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解

    Servlet基础(一) Servlet基础和关键的API介绍 Servlet简介 Java Servlet是和平台无关的服务器端组件,它运行在Servlet容器中. Servlet容器负责Servl ...

随机推荐

  1. Keepalived 安装

    Keepalived 安装安装环境 keepalived-1.2.18.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201 Xshell4 部署方案 201部署 安装步骤  ...

  2. Python: 用shell通配符匹配字符串,fnmatch/fnmatchcase

    问题:想使用Unix Shell 中常用的通配符(比如*.py , Dat[0-9]*.csv 等) 去匹配文本字符串 解决方案: 1. fnmatch 模块提供了两个函数—— fnmatch() 和 ...

  3. python之路----进程二

    守护进程 会随着主进程的结束而结束. 主进程创建守护进程 其一:守护进程会在主进程代码执行结束后就终止 其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic ...

  4. Notepad++ 主题配色配置

    以下方法来源网络,仅供参考: 方案1: 1.主题名称:Obsidian 2.字体字号:Courier New 10 (这里字体你可以随意选择,让自己满意即可) 3.设置方法:设置---语言格式设置-- ...

  5. 20145104张家明 《Java程序设计》第9周学习总结

    20145104张家明 <Java程序设计>第9周学习总结 教材学习内容总结 第16章 -撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找. -JDBC目的:让Java ...

  6. 20145304 网络对抗技术 逆向与Bof基础

    20145304 网络对抗技术 逆向与Bof基础 实践目标 学习以下两种方法,运行正常情况下不会被运行的代码: 手工修改可执行文件,改变程序执行流程,直接跳转到getShell函数. 利用foo函数的 ...

  7. 20145221高其_PC平台逆向破解_advanced

    20145221高其_PC平台逆向破解_advanced 实践目录 shellcode注入 Return-to-libc 攻击实验 shellcode注入 概述 Shellcode实际是一段代码(也可 ...

  8. linux内核分析 1、2章读书笔记

    一.linux历史 20世纪60年代,MIT开发分时操作系统(Compatible TIme-Sharing System),支持30台终端访问主机: 1965年,Bell实验室.MIT.GE(通用电 ...

  9. SQL 收集

    1.union CREATE TABLE dbo.#testTab ( Id int NOT NULL ) insert into #testTab values(); insert into #te ...

  10. Farey Sequence (素筛欧拉函数/水)题解

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...