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 ...
随机推荐
- Confluence 使用常见问题列表
Confluence 6 管理 Atlassian 提供的 App 摘要: Confluence 用户可以使用桌面应用来编辑一个已经上传到 Confluence 的文件,然后这个文件自动保存回 Con ...
- shell入门(二):()、(())、[]、[[]]、{}
1.() 命令组. 括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号’;’隔开,最后一个命令可以没有分号,各命令和括号之间不必有空格. ...
- get方法与post方法的区别与js获取url参数的方式
1.get方法与post方法的区别: 区别一:get重点在从服务器上获取资源,post重点在向服务器发送数据:区别二:get传输数据是通过URL请求,以field(字段)= value的形式,置于UR ...
- python实现简单的登录管理
import json,timeusername=[]userpasswd=[]def login_success_file(name): try: f=open(r"F:/login_su ...
- Java集合实现
set: public class BSTSet<E extends Comparable<E>> implements Set<E> { private BST& ...
- Knockout案例: 全选
- docker+fastdfs+nginx 实现分布式大文件存储系统以及视频缓存播放
废话不多说,直接开撸 首先是一些准备工作: 1.关闭防火墙 service iptables stop --- fastdfs虽然在docker部署,但是使用的是主机网络,所以关闭防火墙. 2 下载 ...
- 【C#】多态
public class Animal { public virtual void Eat() { Console.WriteLine("Animal eat"); Console ...
- Java8新特性----Stream
Stream Stream 是用函数式编程方式在集合类上进行复杂操作的工具. 一)常用的流操作 惰性求值方法:只描述Stream,最终不产生新集合的方法(返回的还是Stream). 及早求值方法:最终 ...
- 使用163.com邮箱发送邮件
不要直接使用登录的密码,而是用配置中的授权码做为密码