beast学习笔记——3,application_controller
参考
1,
(1)代码:
include AuthenticatedSystem
before_filter :set_language
before_filter :login_required, :only => [:new, :edit, :create, :update, :destroy]
(2)表示:
调用插件AuthenticatedSystem,使用前置过滤器,其中login_required只对new, edit, create, update, destroy方法有效
2,
(1)代码
helper :all
helper_method :current_page
(2)表示
【1】helper :all,表示application_controller控制器将include所有的app/helpers目录下的helper。又因为application_controller是根控制器,所以,所有的视图view都可以用所有app/helpers目录下的helper
【2】helper_method方法,可以把controller中的方法定义为helper方法并可以在视图view中应用。又因为application_controller是根控制器,所以,所有的视图view都可以用current_page方法。
3,
(1)代码:
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => 'e125a4be589f9d81263920581f6e4182'
(2)表示
如果没有使用rails2默认的cookie存储session的方式,就需要取消secret的注释,以保证不受CSRF跨站请求伪造。
protect_from_forgery与environment.rb中的config.action_controller.session配合使用
4,
(1)代码
# Filter password parameter from logs
filter_parameter_logging :password
(2)表示
过滤那些不希望被日志文件记录的信息,比如password,从而避免通过日志来泄露敏感信息。
5,
(1)代码
def set_language
I18n.locale = :en || I18n.default_locale
end
(2)表示使用en作为locale,或者使用默认的I18n设置作为locale
I18n是rails2.2以后引入的模块,用于实现框架的国际化。
比方说有这样一个 User model:
# == Schema Information
# Schema version: 20081028111521
#
# Table name: users
#
# id :integer not null, primary key
# login :string(255)
# email :string(255)
class User < ActiveRecord::Base
#...
end
只要在该类中加入以下代码,就可以在 validation 的错误信息中显示中文字段名:
humanize_attributes :login => "用户名",
:email => "电邮"
现在 Rails 2.2 为我们带来了强大的 I18N 功能,没有必要再用上述方法来实现本地化了。
首先,在 environment.rb 中指定本地化语言:
config.i18n.default_locale = :cn
然后在 config/locales 目录下新建 cn.yml 文件,并进行以下设置:
cn:
active record:
models:
user: "用户"
attributes:
user:
login: "用户名"
email: "电邮"
非常优雅方便。
Error messages 也可以用同样的方法进行设置。比方说,以前会用:
validates_presence_of :login, :message => "不能为空"
现在只要在配置文件中加入相应信息即可:
active record:
errors:
messages:
blank: '不能为空'
分享到:
相关推荐
beAst音频小组内部教程_初级第一版 beAst 音频小组@Siluhd 2 目录 前言... 3 一、国语音轨...
EA Beast_2.9
自动趋势线是MT4的一个指示器,它能找出最精确的趋势线,并自动将其绘制在图表上。
BEAST SUPER SIGNAL MT4 INDICATOR
decoder fo zender class php
由C++写的高性能websocket服务端,支持百万连接.
php代码加密扩展 完安装php-beast后可以使用tools目录下的encode_files.php来加密你的项目使用。encode_files.php之前先修改tools目录下的configure.ini文件
php-beast是一个源码加密模块...使用模块提供的beast_encode_file($input_file, $output_file);来加密文件,$input_file为要加密的文件,$output_file为要输出的加密文件。5)把加密好的文件放到服务器上运行。
详细讲解BEAST使用方法和步骤,方便初学者使用
beast加密扩展Windows DLL
3)重启服务器 4)加密PHP文件 使用模块提供的beast_encode_file($input_file, $output_file);来加密文件,$input_file为要加密的文件,$output_file为要输出的加密文件。 5)把加密好的文件放到...
详细介绍如何在windows下编译php-beast扩展,详细介绍了参考网址、编译环境、编译文件、编译步骤等信息
Beauty_and_the_Beast.pdf
Beast2.07软件 Beast2.07软件 Beast2.07软件
信息安全_数据安全_IPv666_–_Address_of_the_Beast 安全评级 安全运营 威胁检测 安全风险 APT
beast2, 基于抽样树的贝叶斯进化分析 Beast 2 Beast 是一种基于分子序列MCMC的贝叶斯推理交叉平台程序。 它完全向根的方向推导,时间测量phylogenies使用严格或者松松的分子时钟模型推断出来。 它可以以作为一种重构...
rails开源论坛 beast源代码下载
主要用于生物进化分析,采用贝叶斯原理构建贝叶斯进化树,软件式操作,免除编程,十分简单方便。附件材料齐全,随下随用。
PHP源码加密模块 PHP source code encrypt module