12月13日 什么是help_method,session的简单理解, find_by等finder method
helper_method
Declare a controller method as a helper. For example,
helper_method :link_to
def link_to(name, options) … end
makes the link_to controller method available in the view.
课程遇到的如current_cart,current_user. 声明后,就可以在view里面使用这个method了。
finder method
find_by: 属于ActiveRecord提供的finder methods 之一。通过传递argument来在database中查找。
The find_by method finds the first record matching some conditions.
find_by!: 和find_by一样,但nill的话,会报错!ActiveRecord::RecordNoFound
find_by_id: find_by_id(params[:id]) ,估计这个用法不再使用了。
http://guides.rubyonrails.org/active_record_querying.html 有22以上中finder methods可用。
(Finder methods that return a collection,such as where and group, return an instance of ActiveRecord::Relation. Methods that find a single entity实体,such as find and first, return a single instance of the model)
session[]: 见http://guides.rubyonrails.org/action_controller_overview.html
详细解释:有整整一章http://guides.rubyonrails.org/security.html
简单说:翻译“一段会话”我的理解就是用于储存的一小块数据,在controller和view中使用,默认是储存在cache缓存中,因此不要储存关键的数据,复杂的数据。
关键翻译:Session are lazily loaded. If youdon't access sessions in your action's code,they will not be loaded.Hence you will never to disable sessions, just not accessing them will do the job.
session是惰性的,如果在action中不使用它,它不会自动加载,所以无需禁用它。
Session Guidlines
1.Do not store large objects in a session.Instead store them in the database and save their id in the session.
2.critical data should not be stored in session.
Session Storage
Rails provides several storage mechanisms(运行机制) for the session hashes. The most important is ActionDispatch::Session::CookieStore
(行为快速处理::一段会话::cookie存储)
retiever(a dog that to find and bring back sth for its master) ;retieve( to find sth and bring it back)
什么是cookiestore:在client-side储存session hash,sever-side可以通过session-id来快速的调用数据,这样有不安全的可能。client可以看到session的内容,Rails4开始使用加密算法 cookie(secrets.secret_key_base)
Replay Attacks for cookiestore sessions :(一种攻击方法。)
解决办法:使用a nonce(a random value)放置在session中,每个nonce只能用一次 。最好的办法还是不要存敏感信心如credit在session中,只在session中保留登陆user_id。
Session Fixation:(一种攻击方法。)
我的理解:攻击者从server端获得一个合法的session并保持长期活跃,然后通过感染页面的方式让用户使用attacker的这个陷阱session,用户始终不知道自己的session被篡改了。
Countermeasure: (应对措施) reset_session使用的Devise gem就有这个代码功能.
每次登陆登出都会自动分配新的session给用户。
Session Expiry:(session到期结束,一个安全方法。)
通过在服务器端设定session的 到期time_stamp 时间。
1.登陆多久后重置session. 但如果attacker在允许的登陆时间内反复登陆可以避开这个办法,所以需要用到下面的2.
2.设置这个session的最长寿命如2天。
delete_all "updated_at < '#{time.ago.to_s(:db)}' OR created_at < '#{2.days.ago.to_s(:db)}'" |
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Arial; color: #3d3d3d; -webkit-text-stroke: #3d3d3d}
span.s1 {font-kerning: none}
12月13日 什么是help_method,session的简单理解, find_by等finder method的更多相关文章
- 2015年12月13日 spring初级知识讲解(四)面向切面的Spring
2015年12月13日 具体内容待补充...
- 2016年12月13日 星期二 --出埃及记 Exodus 21:8
2016年12月13日 星期二 --出埃及记 Exodus 21:8 If she does not please the master who has selected her for himsel ...
- 北京Uber优步司机奖励政策(12月13日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 18.Vim基础指令(自用)——2019年12月13日
title: vim study date: "2018-12-26 20:17:16" tags: 指令学习 categories: 技术驿站 vim study 2018年12 ...
- 【12月13日】A股ROE最高排名
个股滚动ROE = 最近4个季度的归母净利润 / ((期初归母净资产 + 期末归母净资产) / 2). 查看更多个股ROE最高排名 中公教育(SZ002607) - ROE_TTM:92.66% - ...
- 12月13日上午Smarty模版原理
模板主要是用来让前端和后端分离的,前台页面只是一个前台页面,后台页面用php代码写逻辑,写完逻辑拿到前台显示. 一.写法 一般需要以下:写3个页面: 1.显示页面aa.html <!DOCTYP ...
- WinForm 进程、线程、TreeView递归加载、发送邮件--2016年12月13日
进程:一个程序就是一个进程,但是也有一个程序需要多个进程来支持的情况 进程要使用的类是:Process它在命名空间:System.Diagnostics; 静态方法Start(); Process.S ...
- 2017年12月13日 LinQ用法基本的增删改查
LinQ是什么? LinQ是语言集成的查询,是用于C#跟Vb的扩展语言 LinQ的用法 新建一个App_Code文件夹,在文件夹下添加一个数据LinQ to SQL类,可以直接直接点击服务器管理器然后 ...
- 12月16日 增加一个购物车内product数量的功能, 自定义method,在helper中定义,计算代码Refactor到Model中。
仿照Rails实战:购物网站 教材:5-6 step5:计算总价,做出在nav上显示购物车内product的数量. 遇到的❌: 1. <% sum = 0 %> <% current ...
随机推荐
- vim的简单配置
本文大部分内容转载自:https://blog.csdn.net/lhy2932226314/article/details/69668891 vim是从 vi 发展出来的一个文本编辑器.功能丰富,在 ...
- Java代码质量度量工具大阅兵
FindBugs FindBugs, a program which uses static analysis to look for bugs in Java code. It is free so ...
- 20145316许心远《网络对抗》EXP7网络欺诈技术防范
20145316许心远<网络对抗>EXP7网络欺诈技术防范 实验后回答问题 通常在什么场景下容易受到DNS spoof攻击 公共共享网络里,同一网段可以ping通的网络非常容易被攻击 在日 ...
- 我是怎么样和Linux结缘并通过红帽RHCE认证的
我高考完当时就是选择的计算机科学与技术专业,上大学以后联想到的和计算机相关的就只有写代码,开发,网站,网页设计,就没有其他的了,当时学习写代码也都是在Windows上,什么C#.C++之类的?大约在大 ...
- Idea中Maven仓库配置会自动恢复
手头有好几个项目,关闭一个项目,打开另一个项目,发现又在重新下载jar包,打开设置一看,maven配置又恢复到了.m2下边.idea配置的maven会自动恢复吗? 答案是否定的,idea的设置有两个, ...
- 20145105 《Java程序设计》实验二总结
实验二 Java面向对象程序设计 一. 实验内容: 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.多态.建模 初步掌握UML 熟悉S.O.L.I.D原则 了解设计模式 二. 实验步骤 (一 ...
- android 实践项目四
android 实践项目四 本周主要是开发android baidumap实现公交的查询 1.权限的取得和对屏幕的支持 <uses-permission android:name="a ...
- HDU 3746 Cyclic Nacklace(KMP+最小循环节)题解
思路: 最小循环节的解释在这里,有人证明了那么就很好计算了 之前对KMP了解不是很深啊,就很容易做错,特别是对fail的理解 注意一下这里getFail的不同含义 代码: #include<io ...
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- dp入门 专题记录 2017-7-26
POJ3176-Cow Bowling 题目大意:现有n行数,以金字塔的形式排列,即第一行一个数字,第二行2个数字,依次类推,现在需要找一条从第一层到第n层的路线,使得该路线上的所有点的权值和最大 思 ...