Step3: rails g devise:installhtml
這一步執行完後命令行會提醒要手動進行以下動做:session
===============================================================================app
Some setup you must do manually if you haven't yet:url
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:spa
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }命令行
In production, :host should be set to the actual host of your application.orm
2. Ensure you have defined root_url to *something* in your config/routes.rb.
For example:router
root to: "home#index"htm
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
For example:blog
<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頁面之外內容