`
peryt
  • 浏览: 54419 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

7.1.3 active record callback

 
阅读更多

chapter 7.1.3

 

now that our user model has an attr for storing password, we need to arrange to generate and save an encrypted password when save user to the database.

 

the technique of doing this is callback.

 

we will use before_save callback to create the encrypted_password.

 

1. start from test again.

 

we just need to make sure the saved encrypted password is not blank.

 

 

it "should set the encrypted password" do
    @user.encrypted_password.should_not be_blank
end

 

2. next, we will registe a callback called encrypt_password by passing a symbol of that name to before_save method.

 

 

before_save :encrypt_password

private
  def encrypt_password
    self.encrypted_password = encrypt(password)
  end

  def encrypt(string)
    string
  end

 note:

the two method are private methods, it is a good habit to have indentation for private method, which make you fastly deduce this is a private method, or you may get into trouble some time.

 

don't care the difference of private and protect, just use private is enough for you!!!!!!

 

it is a good practice to make method private unless they are needed for the public interface!!

 

These are one-line method, (the best kind!!!)

 

self refer to the object itself. it can't be omitted, or encrypted_password will be a common local variable!!!!

 

but the "password" at the right side can omit self, as it is on the right side!!!

 

 

分享到:
评论

相关推荐

    phpstorm 7.1.3 汉化包

    《PHPStorm 7.1.3汉化包的使用与详解》 PHPStorm是一款由JetBrains公司开发的针对PHP语言的强大的集成开发环境(IDE),它以其高效、智能的代码编辑、调试、测试和版本控制功能深受广大PHP开发者喜爱。在PHPStorm ...

    PowerShell-7.1.3-win-x64.rar

    这个压缩包“PowerShell-7.1.3-win-x64.rar”是针对64位Windows系统的PowerShell 7.1.3安装程序。 PowerShell的核心特性包括: 1. **对象化输出**:与传统的命令行工具不同,PowerShell的输出是对象,而不是纯文本...

    VMware workstation 7.1.3注册机

    VMware workstation 7.1.3注册机,亲自测试,可以正常生成注册码。

    vwmare+7.1.3汉化包

    "vwmare 7.1.3汉化包"是针对VMware Workstation 7.1.3版本的中文语言包,确保用户能够用中文界面操作,提高使用体验,特别是对于中文用户来说,更加友好。 1. **VMware Workstation 7.1.3**:这一版本是VMware在...

    VMware 7.1.3 注册码

    我试过可用,目前还在实用好像没什么问题。如果有问题的话,我不包换的。哈哈

    VMware7.1.3 注册机+汉化补丁

    在本文中,我们将深入探讨VMware 7.1.3版本,特别是关于注册机和汉化补丁的相关知识。 首先,VMware 7.1.3是一个重要的更新,它可能包含了性能优化、新功能的添加以及对先前版本中已知问题的修复。虚拟化技术的核心...

    VMware7.1.3注册机

    在本文中,我们将深入探讨VMware 7.1.3版本及其注册机的相关知识点。 首先,VMware 7.1.3是VMware Workstation产品线的一个重要版本。VMware Workstation是一款桌面级虚拟化软件,它允许用户在单台个人计算机上同时...

    vmware7.1.3 完美汉化版

    VMware Workstation 7.1.3 是一款虚拟机软件,它允许用户在单个物理计算机上运行多个独立的操作系统实例。这个“完美汉化版”意味着该版本已经经过了全面的中文本地化处理,方便中国用户使用。下面将详细介绍这款...

    SecureCRTandSecureFX7.1.3

    《SecureCRT和SecureFX 7.1.3:专业级远程访问与文件传输工具详解》 在IT领域,远程访问和文件传输是日常工作中不可或缺的一部分。SecureCRT和SecureFX是两个备受推崇的工具,分别专注于终端模拟和文件传输,它们以...

    foxmail 7.1.3 官网安装包

    来源于foxmail官网,版本号fm713chb52_build_setup 新增:附件预览 新增:高级搜索与搜索范围切换 新增:往来邮件与往来附件边栏 新增:相关邮件模式 新增:工具栏自定义 新增:常用文件夹自定义 ...

    cuDNN v7.1.3(2018年4月17日),用于CUDA 9.0 windows10版本

    **cuDNN v7.1.3:深度学习加速库** `cuDNN`,全称为`CUDA Deep Neural Network library`,是由NVIDIA公司开发的一个针对深度神经网络(DNN)的高性能计算库。它主要设计用于GPU加速,极大地提升了在训练和推理过程...

    cudnn-9.1-windows7-x64-v7.1.3.zip

    **英伟达cuDNN v7.1.3深度学习库** 英伟达(NVIDIA)的cuDNN(CUDA Deep Neural Network library)是针对深度神经网络(DNN)优化的GPU加速库,专为高性能计算而设计。在这个版本,即cuDNN v7.1.3,它是为CUDA 9.1...

    VMware_Workstation_7.1.3

    VMware_Workstation_7.1.3 有注册码。 可以直接打开lion的映像。 使用前需要打补丁

    dbeaver7.1.3-x86_64-setup.rar

    标题中的“dbeaver7.1.3-x86_64-setup.rar”指的是DBeaver的7.1.3版本的64位安装程序的压缩文件。DBeaver是一款跨平台、开源的数据库管理和开发工具,它支持多种数据库系统,包括但不限于MySQL、Oracle、SQL Server...

    VMware Workstation-7.1.3-324285 序列号

    根据提供的信息,我们可以了解到这是关于VMware Workstation 7.1.3版本的序列号分享。但是,在正式讨论之前,我们需要明确一点:分享和使用未经授权的软件序列号是违反版权法的行为。对于软件的合法使用,我们应该...

    VMware_Workstation7.1.3_汉化补丁.7z和key

    VMware_Workstation7.1.3_汉化补丁.7z

    VMware_Workstation7.1.3_build-324285汉化版

    VMware Workstation 7.1.3是该系列的一个版本,其build-324285指的是这个特定版本的构建号,这通常用于区分软件的不同更新或修复版本。 VMware Workstation的核心功能包括: 1. **多操作系统支持**:在一台物理...

    DeveloperExpress.v7.1.3完美 破解版

    Developer Express .NET v7.1.3 完美 破解版 下载之前请先下载v7.1.3试用版

    cudnn-9.1-windows7-x64-v7.1.3 tensorflow

    标题 "cudnn-9.1-windows7-x64-v7.1.3 tensorflow" 提供的信息主要涉及两个核心组件:CUDA 和 cuDNN,它们是 NVIDIA 为加速深度学习计算而开发的软件库。CUDA 是一个并行计算平台和编程模型,允许程序员利用 NVIDIA ...

    VMware Workstation v7.1.3 Build 324285汉化精简

    VMware Workstation v7.1.3 Build 324285是该系列的一个特定版本,经过了汉化处理,以适应中文用户的使用习惯,并进行了精简,减少了不必要的组件,提高了运行效率。 1. 虚拟化技术:VMware Workstation的核心功能...

Global site tag (gtag.js) - Google Analytics