RoR - Nested Resources, Security ,pagination
root to: 'xxx' 默认root路径
Nested Resource:
Rails.application.routes.draw do
resources :books do
resources :notes # , only: [:create, :destroy]
end root to: "books#index"
end
content_tag:
simple_format: Formats new lines as <br>
Authentication:
has_secure_password #bcrypt-ruby(gemfile)
1. run bundle install
2. make sure password_digest is table column
3.account for password inside strong parameters list in the controller
HTTP Sessions and cookies:
HTTP is a stateless protocol:
1.即使来自同一个浏览器的每个新请求都不知道以前发出的请求。
2.这意味着,即使用户发出请求,他在所有后续请求中都将被视为未知。
Cookies and Sessions to the rescue(keep state)
Sessions in rails:
1.rails 中session 以hash形式来传播
2.服务器向浏览器发送一个cookie,其中包含浏览器存储的会话信息,并在所有后续请求(直到会话结束)时将其发送回服务器
Rails.application.routes.draw do
resources :books do
resources :notes, only: [:create, :destroy]
end resources :sessions, only: [:new, :create, :destroy] root to: "books#index" get "/login" => "sessions#new", as: "login"
delete "/logout" => "sessions#destroy", as: "logout"
end
session controller:


Authorization:
def logged_in?
session[:reviewer_id] # nil is false
end def current_user
@current_user ||= Reviewer.find(session[:reviewer_id])
end
Pagination:
# include will_paginate gem # use in controller def index
@books = current_user.books.paginate(page: params[:page], per_page: 10)
end # use in html.erb <%= will_paginate @books %>
ssl: in production.rb,
uncomment #config.fore_ssl = true
to use https
RoR - Nested Resources, Security ,pagination的更多相关文章
- Android Studio :enable vt-x in your bios security,已经打开还是报错的解决方法
quote: For Windows 10: First of all, install the intelhaxm-android.exe located in the folder SDK\ext ...
- 第二百零九节,jQuery EasyUI,Pagination(分页)组件
jQuery EasyUI,Pagination(分页)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Pagination(分页)组件的使 ...
- 如果你想设置无人自动升级,我们推荐你将这个值修改为security,它会告诉 yum 仅仅升级修复安全问题的软件包。
定期升级你的 CentOS 系统,是所有系统安全中最重要的措施之一.如果你不使用最新的安全补丁升级你的操作系统软件包,你将会让你的机器很容易被攻击. 如果你管理者多个 CentOS 机器,手动升级系统 ...
- SQL Tuning 基础概述06 - 表的关联方式:Nested Loops Join,Merge Sort Join & Hash Join
nested loops join(嵌套循环) 驱动表返回几条结果集,被驱动表访问多少次,有驱动顺序,无须排序,无任何限制. 驱动表限制条件有索引,被驱动表连接条件有索引. hints:use_n ...
- maven打包 springBoot 工程时,默认识别resources目录,习惯使用 resource 目录的需要手动指定静态资源目录
最近项目开发,发现springBoot项目在使用maven打包时,我们静态资源文件都放在resource目录下面,大致如下: 在使用maven打包时,发现静态资源没有打进去.原来springBoot默 ...
- 用Spring Security, JWT, Vue实现一个前后端分离无状态认证Demo
简介 完整代码 https://github.com/PuZhiweizuishuai/SpringSecurity-JWT-Vue-Deom 运行展示 后端 主要展示 Spring Security ...
- springboot中使用spring security,登录url就出现403错误
参考链接:https://segmentfault.com/q/1010000012743613 有两个controller,一个是所有用户可以访问的@RequestMapping("use ...
- Spring Boot 整合 Spring Security,用户登录慢
场景 Spring Boot + Spring Security搭建一个Web项目. 临时用了inMemoryAuthentication. @EnableWebSecurity public cla ...
- Spring Security,没有看起来那么复杂(附源码)
权限管理是每个项目必备的功能,只是各自要求的复杂程度不同,简单的项目可能一个 Filter 或 Interceptor 就解决了,复杂一点的就可能会引入安全框架,如 Shiro, Spring Sec ...
随机推荐
- ApowerMirror投屏(手机投屏电脑、电脑投屏到手机)
使用步骤 1. 亲测 使用Apowersoft ApowerMirror v1.4.2.zip版本 2.Apowersoft ApowerMirror v1.4.2.zip 解压安装 ...
- pm2,部署nodejs,使用方法及自己使用后总结的经验
pm2是一个带有负载均衡功能的应用进程管理器,可以用它来管理你的node进程,并查看node进程的状态,当然也支持性能监控,进程守护等功能.他会确定重启开机之后,能够保证程序也能运行起来.目前还没有操 ...
- robot总结
1 搭建环境地址 http://www.cnblogs.com/yufeihlf/p/5945102.html 2 页面描述 https://www.cnblogs.com/yufeihlf/p/59 ...
- 原生js实现无缝轮播
原生js实现无缝轮播 因为要做到无缝,所以就要把第一张图片和最后一张连接起来,在此处采用js克隆了第一张图片的节点,添加到最后,显示图片序号的小圆按钮也是使用js动态添加的. html部分 <d ...
- 浏览器兼容html头部<meta>标签主要内容详情
<!DOCTYPE html> <head> <meta http-equiv="X-UA-Compatible" content="IE= ...
- mac os安装shell man中文帮助工具(manpages-zh),即man命令显示中文帮助文档
一.从官网(http://pkgs.fedoraproject.org/repo/pkgs/man-pages-zh-CN)下载安装包:或者从开源代码(https://github.com/man-p ...
- docker 中打包部署Springboot项目
1.安装jdk yum -y install java-1.8.0-openjdk* 2.安装并启动mysql mysql高版本驱动变了,最后还是安装5.6 docker pull mysql:5.6 ...
- lintcode 447 Search in a Big Sorted Array(倍增+二分)
题意:给一个按照升序排序的正整数数组.这个数组很大以至于只能通过固定的接口ArrayReader->get(k)来访问第k个数.并且也没有办法得知这个数组有多大.找到给出的整数target第一次 ...
- sklearn模型的属性与功能-【老鱼学sklearn】
本节主要讲述模型中的各种属性及其含义. 例如上个博文中,我们有用线性回归模型来拟合房价. # 创建线性回归模型 model = LinearRegression() # 训练模型 model.fit( ...
- java集成swagger
概览: java集成Swagger Swagger-UI的使用 Springboot跨域请求的访问解决 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 W ...