你打开通知了吗?如果是这样,User
模型正在尝试发送电子邮件通知。如果您尚未配置电子邮件服务器,则创建操作将失败。
我必须执行以下操作才能解决此问题。
1 修改用户模型
添加一个名为dont_notify
.
class User < ActiveRecord::Base
# add a attribute
attr_accessor dont_notify
end
2 更改观察者代码以检测属性。
class UserObserver < ActiveRecord::Observer
def after_create(user)
return if user.dont_notify? #notice this line
UserMailer.deliver_signup_notification(user)
end
def after_save(user)
return if user.dont_notify? #notice this line
UserMailer.deliver_activation(user) if user.recently_activated?
end
end
3dont_notify
在播种期间设置标志
在你seed.rb
设置标志。
User.create(:login => 'admin',
:role => Role.find_by_name('super_admin'),
:email => 'admin@example.com',
:password => '123123',
:password_confirmation => '123123',
:dont_notify => true
)