rails中使用devise

refer to:  https://github.com/plataformatec/devise

# Gemfile
gem 'devise'

# 运行下面三个命令

$ bundle exec rails generate devise:install
$ bundle exec rails generate devise user
$ bundle exec rails g devise:views

# application controller 增加:: 
class ApplicationController < ActionController::Base
  before_action :authenticate_user!
end

# 为application.html.erb 增加 登录 ,退出等按钮
          <% if user_signed_in? %>        
          
          <% else %>
          
          <% end %>

几个核心方法:

user_signed_in? 判断用户是否登录

current_user 获取当前用户


你可能感兴趣的:(rails中使用devise)