rails4.2~devise邮箱测试
2015-06-04 22:02
337 查看
1.由于网站无需验证,只需一封欢迎邮件,在config/intiailzers/devise.rb里面配置
config.allow_unconfirmed_access_for = nil #2.days
2.配置user--编辑app/models/user.rb文件,先写一下数据这一块
3.编辑20150504141218_devise_create_users.....对照代码去掉#即可
发现报错
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
With Strong Parameters, attribute whitelisting has been moved to controller level. Remove the
Here is an example in Rails Guide of how to use Strong Parameters
In your case you can do something like this:
之后就删除了
然后重新部署数据库,才能重新检测同一个邮箱是否接受邮件,你也可以重新换一个邮箱注册,因为没有修改config/下面的文件
rake db:migrate:reset
2.先测试下,邮件服务器配置config/initialize/devise.rb
3.编辑/config/application.rb,将下列代码添加到class Application < Rails::Application中即可,本人使用的是qq邮箱发送,需要提前去qq邮箱里面打开相应的smtp服务
4.本人是用qq测的,所以也按照上面的方法,但还是不行,页面报错535 Authentication failed
百度了半天还是不行,后来看到了 https://ruby-china.org/topics/8918 这个帖子
![](http://images0.cnblogs.com/blog2015/763366/201506/042138369414085.png)
看到企业邮箱是加了@XXX.com,那我这个是个人的邮箱,应该不需要就删掉了这些.....
然后ctrl+C关闭rails服务器,然后rake db:migrate:reset,重新注册用户....居然发送成功了,来张截图
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
3.编辑20150504141218_devise_create_users.....对照代码去掉#即可
## 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_accessibleis 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_accessiblecall 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
,
:password
,
:password_confirmation
,
:remember_me
end
然后重新部署数据库,才能重新检测同一个邮箱是否接受邮件,你也可以重新换一个邮箱注册,因为没有修改config/下面的文件
rake db:migrate:reset
2.先测试下,邮件服务器配置config/initialize/devise.rb
config.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 这个帖子
![](http://images0.cnblogs.com/blog2015/763366/201506/042138369414085.png)
看到企业邮箱是加了@XXX.com,那我这个是个人的邮箱,应该不需要就删掉了这些.....
然后ctrl+C关闭rails服务器,然后rake db:migrate:reset,重新注册用户....居然发送成功了,来张截图
![](http://images0.cnblogs.com/blog2015/763366/201506/042144252699801.png)
相关文章推荐
- hdu 5009 Paint Pearls
- HDU 2476 - String painter(区间DP)
- 【leetcode】Contains Duplicate II
- suspend() 和 resume() 方法,notify()和wait()方法区别
- Splay树(区间添加删除 | 区间翻转)——HDU 3487 Play with Chain
- sizeWithFont:constrainedToSize:转boundingRectWithSize:options:
- msdb.dbo.sp_send_dbmail 用法简介
- MacBook Air装单独win7
- Message和obtainMessage的区别
- hdu 2057 a + b again
- Database mail 配置
- 魔狼地址:https://bitbucket.org/moLangZaiShi/demo/downloads
- Root lenovo A916(failed) and Sony Xperia T2 Ultra
- Filter及FilterChain的使用具体解释
- 安卓真机调试之 INSTALL_FAILED_MEDIA_UNAVAILABLE
- xcode新建工程时出现fatal: unable to auto-detect email address (got 'Rabstone@bogon.(none)')错误
- Container With Most Water
- 从main函数启动过程说起
- LightOJ - 1038 Race to 1 Again 递推+期望
- poj2709Painter