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 ...
随机推荐
- 响应消息的内容类型 text/html; charset=utf-8 与绑定(application/soap+xml; charset=utf-8)的内容类型不匹配。
问题表述: 响应消息的内容类型 text/html; charset=utf-8 与绑定(application/soap+xml; charset=utf-8)的内容类型不匹配. 说明: 此类问题当 ...
- nginx+iis使用
一.nginx的介绍 nginx是由俄罗斯人开发的一款高性能的http和反向代理服务器,也可以用来作为邮件代理.相比较于其他的服务器,具有占用内存少,稳定性高等优势 Nginx相关地址 源码:http ...
- 洛谷P5206 [WC2019]数树 [容斥,DP,生成函数,NTT]
传送门 Orz神仙题,让我长了许多见识. 长式子警告 思路 y=1 由于y=1时会导致后面一些式子未定义,先抓出来. printf("%lld",opt==0?1:(opt==1? ...
- 用JS实现实时显示系统时间
废话我就不多说了,直接上图和代码了 效果图: 代码视图: 下面为大家附上代码,复制即可用: <!DOCTYPE html> <html lang="en"> ...
- js 读取文件
读取文本文件 读取文本文件: <input type="file" id="file1" accept="*" /> </ ...
- TCP报文首段格式
参考:https://www.bilibili.com/video/av9876107?from=search&seid=5217429010533979778 TCP(Transmissio ...
- highcharts的dataLabels如何去处阴影
问题: 在使用highcharts生成的图标中dataLabels是有阴影的,通常是影响美观,那么如何去除阴影呢? 原因:是因为highcharts将dataLabels生成的标签是tspan,里面有 ...
- Python-uiautomator使用说明文档
https://github.com/xiaocong/uiautomator 这个Python库是基于Android自带的uiautomator测试框架的一个python封包.适用于Android ...
- spark DataFrame的创建几种方式和存储
一. 从Spark2.0以上版本开始,Spark使用全新的SparkSession接口替代Spark1.6中的SQLContext及HiveContext接口来实现其对数据加载.转换.处理等功能.Sp ...
- 一步一步安装SQL Server 2017
快速开始: 下载安装文件:https://www.microsoft.com/en-us/sql-server/sql-server-downloads-free-trial 应该选择哪个版本? Th ...