1、gem install devise
2、在gemfile中添加 gem 'devise'
3、bundle install
4、执行 rails generate devise:install
5、配置config/environment/development.rb中,添加
config.action_mailer.default_url_options={:host=>'localhost:3000'}
6、route中添加
root :to=>'home#index'
7、application.html.erb中添加
<p class="notice"><%=notice%></p>
<p class="alert"><%=alert%></p>
8、执行rails generate devise User
9、修改migrate/DeviseCreateUser,修改models/User.rb改成自己需要的内容
10、rake db:migrate
11、生成自定义视图
rails generate devise:views
12、设置config/development.rb里的邮箱
config.action_mailer.default_url_options={:host=>'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.163.com",
:port => 25,
:domain => "163.com",
:authentication => :login,
:user_name => "", #你的邮箱
:password => "******" #你的密码
}
13、应用于controller,before_filter :authenticate_user!
获取当前用户current_user