用户认证是一个整体的模块,如何快速集成devise,能极高的提高我们的程序开发速度。
gem "devise", '2.1.0'
rails generate devise:install
rails generate devise user
rake db:migrate
rails generate devise:views users
需要设置config.scoped_views = true
才行zh:
errors:
messages:
not_found: "没有找到"
already_confirmed: "已经确认"
not_locked: "没有锁定"
devise:
failure:
unauthenticated: '继续操作前请注册或者登录.'
unconfirmed: '请先激活您的帐号'
locked: '您的帐号已被锁定.'
invalid: '手机号或密码错误'
invalid_token: '认证码无效.'
timeout: '您已登录超时,请重新登录.'
inactive: '您还没有激活帐户.'
already_authenticated: "您已经登录了."
sessions:
signed_in: '登录成功.'
signed_out: '退出成功.'
passwords:
send_instructions: '几分后,您将收到重置密码的电子邮件.'
updated: '您的密码已修改成功,请重新登录.'
confirmations:
send_instructions: '几分后,您将收到帐号激活的电子邮件.'
confirmed: '您的帐号已经激活,请登录.'
registrations:
signed_up: '您的帐号已注册成功.'
updated: '帐号资料更新成功.'
destroyed: '再见!您的帐户已成功注销。我们希望很快可以再见到您.'
unlocks:
send_instructions: '几分后,您将收到一封帐号解锁的邮件.'
unlocked: '您的帐号已成功解锁,请登录.'
mailer:
confirmation_instructions:
subject: '确认信息'
reset_password_instructions:
subject: '重置密码信息'
unlock_instructions:
subject: '解锁信息'
class ApplicationController < ActionController::Base
private
# 注销成功后
def after_sign_out_path_for(resource_or_scope)
root_path
end
end
def after_sign_in_path_for(resource_or_scope)
categories_path
end
rails g controller users::sessions
devise_for :users, :controllers => { :sessions => "users/sessions" }
before_filter :authenticate_user!
user_signed_in?
current_user
user_session
devise_for :users, :controllers => { :sessions => "users/sessions" },
:path_names => { :sign_in => 'login', :sign_out => 'logout'},
:skip => [:registrations, :passwords]