使用 callback 确保创建,更新和删除 Picture 时,touch 关联的 imageable,使得其缓存能正确过期

这个update的方法用来把update时间强制更新成当前时间

http://guides.rubyonrails.org/association_basics.html

4.1.2.9 :touch

If you set the :touch option to true, then the updated_at or updated_on timestamp on the associated object will be set to the current time whenever this object is saved or destroyed:

class Book < ApplicationRecord
belongs_to :author, touch: true
end class Author < ApplicationRecord
has_many :books
end

由于在多态关联中直接写touch :true没有起作用,写了另一个方法

class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true validates_uniqueness_of :name, scope: [:imageable_id, :imageable_type] after_save :touch_imagable
after_destroy :touch_imagable def touch_imagable
imageable.touch
end
end

imageable.touch的更多相关文章

  1. mkdir,rmdir,cp,rm,mv,cat,touch用法

    一.mkdir新建目录 1.进入tmp目录,查看该目录下面的子目录 [root@localhost ~]# cd /tmp[root@localhost tmp]# lshsperfdata_root ...

  2. UC浏览器中touch事件的异常记录

    以前也在UC上面栽过几个坑,不过都是页面显示方面的.上个周的时候,商品详情页重做,要添加个上拉显示详情的效果. 有两个条件需要判断: 1.是否到达底部: 2.到达底部之后拖动的y轴距离. 效果写完后, ...

  3. 移动端web开发,click touch tap区别

    转自: http://blog.csdn.net/sly94/article/details/51701188 移动端用tap时会有穿透问题 一:click与tap比较 click与tap都会触发点击 ...

  4. 手机端html5触屏事件(touch事件)

    touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend:触摸结束的时候触发 而每个触摸事件都包括了三个触摸列表,每个列表里包含了对应的一系列触摸点( ...

  5. 移动端开发概览【webview和touch事件】

    作为一个前端,而且作为一个做移动端开发的前端,那意味着你要有三头六臂,跟iOS开发哥哥一起打酱油,跟Android开发哥哥一起修bug... Android vs Ios 我在webkit内核的chr ...

  6. 手持设备点击响应速度,鼠标事件与touch事件的那些事

    前言 现在一直在做移动端的开发,这次将单页应用的网页内嵌入了app,于是老大反映了一个问题:app应用点击响应慢!我开始不以为然,于是拿着网页版的试了试,好像确实有一定延迟,于是开始了研究,最后选择了 ...

  7. touch

    Linux touch 命令   在 Linux 下运用 touch 命令创建一个空文件.当然我们也可以使用其他命令例如 vi, nano 或是任意一个编辑工具来实现.但是你可能需要更多的步骤来完成操 ...

  8. touch命令

    [touch]      改变文件的时间戳 命令格式: touch [OPTION]... FILE... 命令功能: 更新每个文件的访问和修改时间到当前时间或建立一个不存在的文件 命令参数: -a  ...

  9. iOS 事件传递(Touch事件)

    先总说如下: 1.当手指触摸到屏幕时,会产生UITouch对象和UIEvent对象. 2.这两个对象产生后会被传递到UIApplication管理的一个事件队列中. 3.再有UIApplication ...

随机推荐

  1. Python实现打印二叉树某一层的所有节点

    不多说,直接贴程序,如下所示 # -*- coding: utf-8 -*- # 定义二叉树节点类 class TreeNode(object): def __init__(self,data=0,l ...

  2. win7开防火墙,允许ping通

  3. eclipse自动部署问题

    1. 使用myeclipse自动部署的方法(使用myeclipse 2015自动部署有问题,待解决)(换成2014的便可以自动部署): 1.Window->preferences->Mye ...

  4. Request.GetOwinContext()打不到

    Although it's in the Microsoft.Owin.Host.SystemWeb assembly it is an extension method in the System. ...

  5. Lua 之table库

    标准table库 table.concat(table, sep,  start, end) concat是concatenate(连锁, 连接)的缩写,table.concat()函数列出参数中指定 ...

  6. phpcms v9 0day

    index.php?m=member&c=index&a=login 后缀 username=phpcms&password=123456%26username%3d%2527 ...

  7. Yii2.0 实现的短信发送

    原文地址:http://www.phpxs.com/post/4245/ yii2-smserGithub项目主页 https://github.com/daixianceng/yii2-smser ...

  8. Yii2 行为

    // Step 1: 定义一个将绑定行为的类 class MyClass extends yii\base\Component { // 空的 } // Step 2: 定义一个行为类,他将绑定到My ...

  9. verilog阻塞与非阻塞的初步理解(一)

    通过两个模块来区别两者.测试平台:Modelsim altera 6.5b 阻塞模块: module blocking(clk,a,b,c); :] a; input clk; :] b,c; :] ...

  10. xStream完美转换XML、JSON

    xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...