3-30 flash(api),rescue_from(); logger简介
ActionDispatch::Flash < Objec
pass temporary primitive-types (String, Array, Hash) 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简介的更多相关文章
- 没有任何秘密的 API:Vulkan* 简介
Vulkan 被视作是 OpenGL 的后续产品. 它是一种多平台 API,可支持开发人员准备游戏.CAD 工具.性能基准测试等高性能图形应用. 它可在不同的操作系统(比如 Windows*.Linu ...
- KnockoutJS 3.X API 第一章 简介
本文纯正翻译自官网API文档.其中包含一下个人理解. 官网API地址:http://knockoutjs.com/documentation/introduction.html 简介 Knockout ...
- 0601-Zuul构建API Gateway-API gateway简介、基础使用、路由配置、负载配置
一.API Gateway简介 参看:http://www.cnblogs.com/bjlhx/p/8794437.html 二.zuul简介[路由器和过滤器:Zuul] 在微服务架构的组成部分进行路 ...
- ASP.NET Core 3.0 WebApi中使用Swagger生成API文档简介
参考地址,官网:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view ...
- Android开发-API指南-Android简介
Introduction to Android 英文原文:http://developer.android.com/intl/zh-cn/guide/index.html 采集日期:2014-4-16 ...
- JDK Logger 简介 (zhuan)
http://antlove.iteye.com/blog/1924832 ******************************************* 一 简述 java.util.log ...
- 22 | 从0到1:API测试怎么做?常用API测试工具简介
- Java的常用API之包装类简介
包装类 包装类: 基本数据类型,使用起来非常方便,但是没有对应的方法来操作这些基本类型的数据可以使用一个类,把基本类型的数据装起来,在类中定义一些方法,这个类叫做包装类,我们可以使用类中的方法来操作这 ...
- Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解
Servlet基础(一) Servlet基础和关键的API介绍 Servlet简介 Java Servlet是和平台无关的服务器端组件,它运行在Servlet容器中. Servlet容器负责Servl ...
随机推荐
- Linux命令: 在线练习网址
1.https://www.tutorialspoint.com/unix_terminal_online.php 2.从 这里 https://www.tutorialspoint.com/inde ...
- maven intall在target文件夹中自动生成的war包部署服务器时缺斤少两
1.问题描述,本地改动特别大或者升级系统操作,打war包部署服务器上程序时候,页面或者后台总是报错,原因就是比本地少东西. 2.问题排查解决:maven clean然后maven intall在tar ...
- MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance
终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...
- MVC 扩展RadioButtonListFor和CheckBoxListFor
学习MVC时候前端通常会用到HtmlHelper,使得前端编码简便很多.我们可能会经常用到htmlHelper中一些的EditorFor,LabelFor,ValiationMessageFor, 发 ...
- 20145109竺文君、20145106石晟荣 java实验三
重构的概念:重构(Refactoring)就是通过调整程序代码改善软件的质量.性能,使其程序的设计模式和架构更趋合理,提高软件的扩展性和维护性. 首先由zwj在<git.oschina.net& ...
- 《课程设计》——foremost的使用
<课程设计>--foremost的使用 foremost简介 formost 是一个基于文件头和尾部信息以及文件的内建数据结构恢复文件的命令行工具.这个过程通常叫做数据挖掘(data ca ...
- 20145310 Exp8 Web基础
实验问题回答 (1)什么是表单 表单在网页中主要负责数据采集功能. 表单是一个包含表单元素的区域,表单元素是允许用户在表单中(比如:文本域.下拉列表.单选框.复选框等等)输入信息的元素. 表单的三个基 ...
- scp命令在linux间传送文件的方法
当两台LINUX主机之间要互传文件时可使用SCP命令来实现,建立信任关系之后可不输入密码. 把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中 ...
- python程序转为exe文件
python开发者向普通windows用户分享程序,要给程序加图形化的界面(传送门:这可能是最好玩的python GUI入门实例! http://www.jianshu.com/p/8abcf73ad ...
- Linux系统编程之--守护进程的创建和详解【转】
本文转载自:http://www.cnblogs.com/mickole/p/3188321.html 一,守护进程概述 Linux Daemon(守护进程)是运行在后台的一种特殊进程.它独立于控制终 ...