Step1: Gemfile中加入gem 'devise'

Step3: rails g devise:install

这一步执行完后命令行会提醒要手动进行如下动作:

===============================================================================

Some setup you must do manually if you haven't yet:

1. Ensure you have defined default url options in your environments files. Here
is an example of default_url_options appropriate for a development environment
in config/environments/development.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

In production, :host should be set to the actual host of your application.

2. Ensure you have defined root_url to *something* in your config/routes.rb.
For example:

root to: "home#index"

3. Ensure you have flash messages in app/views/layouts/application.html.erb.
For example:

<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>

4. You can copy Devise views (for customization) to your app by running:

rails g devise:views

Step4:  rails g devise User

Step6: rake db:migrate

最后,我们可以看看generator在router.rb文件中的devise_for都产生了什么路由.我们可以通过rake routes,结果如下:

可以把devise的登录页面作为系统首页,设置方式为在routes.rb文件中设置如下信息:

devise_scope :user do
    root to: "devise/sessions#new"
  end

或者

devise_scope :user do

unauthenticated :user do
        root to: "devise/sessions#new",as: :unauthenticated_root #设定登录页为系统默认首页
    end
    authenticated :user do
        root to: "homes#index",as: :authenticated_root #设定系统登录后首页
    end

end

application_controlller中加入以下代码

before_action :authenticate_user!     #权限控制,管控仅登录用户方可访问login页面以外内容

gem devise配置的更多相关文章

  1. devise 小项目(一)

    Devise源于Warden,而warden是一个基于Rack的验证权限gem,不过,使用devise实际并不需要任何关于warden的知识. 如果你之前有一些其他类似的维护验证权限功能的gem的使用 ...

  2. 转:devise使用

    1.gem install devise 2.在gemfile中添加 gem 'devise' 3.bundle install 4.执行 rails generate devise:install ...

  3. rails权限管理—devise+cancan+rolify

    使用devise.cancan和rolify组件建立用户权限模型的说明. devise:负责用户注册.登录.退出.找回密码等操作.细节参考devise on github cancan:负责角色建立. ...

  4. 【WIP】Rails devise导入与使用方法

    创建: 2017/09/07 更新: 2017/10/14 标题加上[WIP]     源代码: https://github.com/plataformatec/devise  命令行内容总结  安 ...

  5. Ruby On Rails 常用的精品Gem汇总

    首先需要注明一点,本文是原创的并不是从其它地方转载.所有的数据是我从 GitHub 和 RubyGems 上码下来的,数据的截取时间就是本文的发布日期. RubyGems 的下载量可以看到在用这个 g ...

  6. rails devise使用

    gem 'devise'rails g devise:install Userrails g devise Userrails g devise:views

  7. gem update --system 302 错误 解决方案(转)

    具体过程如下: 1.InstantRails-2.0安装后,在配置环境变量path中配置ruby/bin目录(如果系统中有多个RUBY,执行命令行的时候系统认的就是path中的) 2.进入DOS命令行 ...

  8. Ruby on Rails: 使用devise+cancan+rolify建立完整的权限管理系

    devise.cancan和rolify这三个组件结合,可以建立完整而强大的用户权限模型. devise介绍,负责用户注册.登录.退出.找回密码等操作.细节参考devise on github can ...

  9. (GoRails )使用Vue.js制作拖拉list功能(v1-4) gem 'acts_as_list'(自动排列顺序)

    系列视频: use Vue.js to build the drag and drop support for the list themselves the cards that are under ...

随机推荐

  1. 芝麻HTTP:在阿里云上测试Gerapy教程

    1.配置环境 阿里云的版本是2.7.5,所以用pyenv新安装了一个3.6.4的环境,安装后使用pyenv global 3.6.4即可使用3.6.4的环境,我个人比较喜欢这样,切换自如,互不影响. ...

  2. CF374 Maxim and Array

    贪心 如果有0先变成非0 如果负数的个数 应该变为偶数 之后就是每次将绝对值最小的值加K #include<bits/stdc++.h> using namespace std; cons ...

  3. BOM(浏览器对象模型)的一些操作

    一个完整的JavaScript实现由三部分组成: ECMAScript:核心,定义语言基础,规定了语言的组成部分(语法,类型,关键字,保留字,对象等) DOM:文档对象模型,·DOM把整个页面映射成一 ...

  4. form表单的action提交写到js中来,同时onclick事件也写在js中来。其action也可以通过ajax来提交的。

    1,html脚本 <body> <div style="display: none;"> <form id="submitForm" ...

  5. 异常-----Template user.ftl not found

    freemarker 1.错误描述 java.io.FileNotFoundException: Template user.ftl not found. at freemarker.template ...

  6. ASP.NET MVC 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction

    1.Action.RenderAction加载办法的视图,履行Controller → Model → View的次序,然后把产生的页面带回到本来的View中再回传.而Partial.RenderPa ...

  7. NOIP2010题解

    所有题目链接均来自洛谷 T1机器翻译 原题戳这里 自古T1是水题 因为每一个数字都小于1000,所以对于是否在队列中可以开数组查询 对于大小的限制,弄一个队列维护大小即可(水题呀...) 这题在Win ...

  8. [JSOI2008]球形空间产生器sphere

    Sol 设一个dis,就有n+1个方程,消掉dis,就只有n个方程,组成一个方程组,高斯消元就好(建议建立方程时推一下,很简单) # include <bits/stdc++.h> # d ...

  9. c#抽取pdf文档标题(4)——机器学习以及决策树

    我的一位同事告诉我,pdf抽取标题,用机器学习可以完美解决问题,抽取的准确率比较高.于是,我看了一些资料,就动起手来,实践了下. 我主要是根据以往历史块的特征生成一个决策树,然后利用这棵决策树,去判断 ...

  10. 11.C++-临时对象分析

    首先来参考以下代码: #include <stdio.h> class Test { int mi; public: Test(int i) { mi = i; } Test() { Te ...