rails4.2~devise邮箱测试
1.由于网站无需验证,只需一封欢迎邮件,在config/intiailzers/devise.rb里面配置
config.allow_unconfirmed_access_for = nil #2.days
2.配置user--编辑app/models/user.rb文件,先写一下数据这一块
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, #末尾添加,号
:confirmable, :lockable #添加这一行 # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
## Confirmable
t.string :confirmation_token #去掉首位注释#号 t.datetime :confirmed_at #去掉首位注释#号 t.datetime :confirmation_sent_at #去掉首位注释#号 t.string :unconfirmed_email # Only if using reconfirmable #去掉首位注释#号 ## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both #去掉首位注释#号 t.datetime :locked_at #去掉首位注释#号 -----------------------------.
发现报错
rake aborted!
NoMethodError: undefined method `attr_accessible' for User (call 'User.connection' to establish a connection):Class
之后百度找到
http://stackoverflow.com/questions/23743603/undefined-method-attr-accessible-error-for-user
attr_accessible is not available for Rails version 4+. You would have to go with strong parameters.
With Strong Parameters, attribute whitelisting has been moved to controller level. Remove the attr_accessible call from your model.
Here is an example in Rails Guide of how to use Strong Parameters
In your case you can do something like this:
class UsersController < ApplicationController
## ...
def create
@user = User.new(user_params) ## Invoke user_params method
if @user.save
redirect_to @user, notice: 'User was successfully created.'
else
render action: 'new'
end
end
## ... private
## Strong Parameters
def user_params
params.require(:user).permit(:name, :password_digest, :password, :password_confirmation)
end
end
之后就删除了attr_accessible :email, :password, :password_confirmation, :remember_me
endconfig.mailer_sender = 'XXXXXXXX@qq.com' #将邮件服务器地址写成自己的邮箱,作为发送方邮件
3.编辑/config/application.rb,将下列代码添加到class Application < Rails::Application中即可,本人使用的是qq邮箱发送,需要提前去qq邮箱里面打开相应的smtp服务
config.action_mailer.raise_delivery_errors = true #注意,在development.rb下需修改成true
#添加如下几行代码
config.action_mailer.default_url_options = { :host => "localhost:3000" } #提示中有提到需要配置,即执行rails g devise:install
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.qq.com",
:port => 25,
:domain => "qq.com", #qq.com
:authentication => :login,#几种认证方式:plain,直接传递;login,Base64码传递;cram_md5,md5加密传递
:user_name => "xxxxxxx@qq.com", #修改邮箱
:password => "xxxxxxxx" #修改正确的密码 }
4.本人是用qq测的,所以也按照上面的方法,但还是不行,页面报错535 Authentication failed
百度了半天还是不行,后来看到了 https://ruby-china.org/topics/8918 这个帖子

看到企业邮箱是加了@XXX.com,那我这个是个人的邮箱,应该不需要就删掉了这些.....
然后ctrl+C关闭rails服务器,然后rake db:migrate:reset,重新注册用户....居然发送成功了,来张截图

rails4.2~devise邮箱测试的更多相关文章
- SSL邮件发送(腾讯企业邮箱测试通过,可以支持多附件)
参考网址:http://www.cnblogs.com/LUA123/p/5575134.html ,谢谢! package net.common.utils.common; import java. ...
- C# 发送邮件,QQ企业邮箱测试成功
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- c# 发送邮箱,企业邮箱测试成功
今天在项目中需要实现一个发送邮箱的功能,来实现用户邮箱激活功能!!! 之前采用的是个人的邮箱进行测试,一切都是很顺利的,后来换成了公司的企业邮箱,遇到了一点小问题,问题如下: 发送邮件失败,原因:命令 ...
- 已使用 163 邮箱测试通过,且支持 SSL 连接。 发送邮件
示例:Jack 发送一封邮件给 Rose. public class SendMail { public static void main(String[] args) { b ...
- 杂项之使用qq邮箱发送邮件
杂项之使用qq邮箱发送邮件 本节内容 特殊设置 测试代码 1. 特殊设置 之前QQ邮箱直接可以通过smtp协议发送邮件,不需要进行一些特殊的设置,但是最近使用QQ邮箱测试的时候发现以前使用的办法无法奏 ...
- JavaMail简单版实验测试
前言: 最近由于实现web商城的自动发送邮件功能的需求,故涉猎的邮箱协议的内部原理.现将简单版的Java Mail实例做个代码展示,并附上其中可能出现的bug贴出,方便感兴趣的读者进行测试! 1.载入 ...
- QQ邮箱发送邮件,出现mail from address must be same as authorization user错误
之前做的一个系统,有个发送邮件的功能,一直能正常使用,今天同事说QQ邮箱发送不了. 立马着手调试,发现服务器一直出现“mail from address must be same as authori ...
- qq邮箱发送
454 Authentication failed, please open smtp flag first!用QQ邮箱测试报错 我用QQ邮箱测试javamail发送邮件的功能,用户名密码设置正确,却 ...
- Google Play 购买(IAB)测试流程
Google Play 购买(IAB)测试流程 0. 前言 虽然Google 官方也有说明,但是说话很含糊(英文原文也很含糊),很多时候不清楚它到底表达什么.而且帮助文档和开发文档是分开的,可能常常出 ...
随机推荐
- 说说JSON和JSONP,也许你会豁然开朗(转)
前言 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socke ...
- leveldb 学习笔记之log结构与存取流程
log文件的格式 log文件每一条记录由四个部分组成: CheckSum,即CRC验证码,占4个字节 记录长度,即数据部分的长度,2个字节 类型,这条记录的类型,后续讲解,1个字节 数据,就是这条记录 ...
- WEB中的GET和POST
客户端提交数据到服务器端有两种方式GET和POST,get是将数据拼接到url上,而post是将数据封装在request body中,发送过去.顾名思义,get即请求数据,有时需要其附带部分参数:po ...
- easyui 下拉树改造
<select id="cc" style="width: 250px"></select> <div id="sp&q ...
- Oracle循环查询结果集 自定义函数
create or replace function Fun_GetRoleIDList(d_fid char) return varchar is rolelist varchar(2000);b ...
- JavaScript导出excel文件实现
function getXlsFromTbl(inTblId, inWindow, fname) { try { var allStr = ""; var curStr = &qu ...
- C#中 字符串转换为计算公式
//方法一 利用DataTable中的Compute方法 例如:1*2-(4/1)+2*4=6 string formulate = string.Format("{0}*{1} - {2} ...
- 解决mac升级后,出现的 xcrun: error: invalid active developer path, missing xcrun 错误
最近升级了mac系统,然后接着写代码就出问题了. 报错信息如下: xcrun: error: invalid active developer path (/Library/Developer/Com ...
- 发布以NLog作为日记工具的ASP.NET站点到IIS注意事项
一.可以通过在Web.Config文件中添加节点来配置,或是直接将NLog.config放在Web.config所在目录 二.通过节点的fileName属性指定日志文件规则时,可以使用${basedi ...
- mysql备份文件注释乱码处理工具
我们有时候需要做mysql数据库的注释,可是备份出来的是乱码,怎么办呢? 本工具软件来帮你的忙. 将GBK库备份后的文本文件中夹带的UTF8乱码转换为GBK编码,就不再乱码了. http://down ...