Heroku上的RoR - 点击确认链接后电子邮件未得到确认

时间:2015-04-25 18:01:59

标签: ruby-on-rails ruby heroku confirm

好的,所以我创建了一个带注册系统的应用程序。我在Heroku上成功部署了应用程序。我可以注册用户并确认链接进入他们的收件箱。但是当他们点击链接时,它会在heroku上显示“Something failed ...”。

确认链接如下:appname.herokuapp.com/users/WTIh-I_Ti5IF8ikfD6qaWw/confirm_email

如果有人回复,我真的很感激!

我的用户控制器:

require 'digest/md5'

class User < ActiveRecord::Base

before_create :confirmation_token

before_validation :prep_email

    def create_avatar_url
        self.avatar_url = "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email)}?s=50"
    end

has_secure_password

validates :name, presence: true
validates :username, uniqueness: true, presence: true
validates :email, uniqueness: true, presence: true, format: { with: /\A[\w.+-]+@([\w]+.)+\w+\z/ }

def email_activate
    self.email_confirmed = true
    self.confirm_token = nil
    save!(:validate => false)
end

private

def prep_email
    self.email = self.email.strip.downcase if self.email
end

def confirmation_token
  if self.confirm_token.blank?
      self.confirm_token = SecureRandom.urlsafe_base64.to_s
  end
end

我的users.rb

    def create
user = User.find_by_username(params[:username])
if user && user.authenticate(params[:password])
  if user.email_confirmed
    session[:user_id] = user.id
    redirect_to root_url, notice: "Logged in!"
else
    flash.now[:error] = 'Please activate your account by following the 
    instructions in the account confirmation email you received to proceed'
end


else
    flash.now[:error] = "Invalid user/pass"
  end
  end

  def destroy
    session.delete(:user_id)
    redirect_to root_url, notice: "Logged out."
  end

会话控制器:

class UserMailer < ActionMailer::Base

default :from => "no-reply@domain.com"

def registration_confirmation(user)
    @user = user
    mail(:to => "#{user.name} <#{user.email}>", :subject => "Registration Confirmation")
end

end

app / mailers / user_mailer.rb

     resources :users do
    member do
      get :confirm_email
    end

 end

还将此添加到我的路线文件

Hi <%= @user.name %>,

Thanks for registering! To confirm your registration click the URL below.

<%= confirm_email_user_url(@user.confirm_token) %>

还在我的app / views / user_mailer / registration_confirmation.text.erb中添加了text.erb文件

      # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default_url_options = {:host => "localhost:3000"}
  config.action_mailer.delivery_method = :smtp 
  config.action_mailer.smtp_settings = { 
    address: 'smtp.gmail.com', 
    port: 587, 
    domain: 'gmail.com', 
    user_name: 'mygmail@gmail.com', 
    password: 'mypassword', 
    authentication: 'plain', 
    enable_starttls_auto: true
   }

developers.rb中的SMTP设置

2015-04-25T08:06:21.545018+00:00 heroku[web.1]: State changed from starting to up

2015-04-25T08:06:22.709790+00:00 heroku[router]: at=info method=GET path="/" host=keplarblog4.heroku
app.com request_id=d1497cc9-02f1-4b55-8f72-a2efd95faf7a fwd="117.102.24.185" dyno=web.1 connect=0ms
service=267ms status=200 bytes=2847

2015-04-25T08:06:23.174505+00:00 heroku[router]: at=info method=GET path="/less.js" host=keplarblog4
.herokuapp.com request_id=1d6643da-a068-48e0-bc7f-1fc9c18af1af fwd="117.102.24.185" dyno=web.1 conne
ct=0ms service=6ms status=304 bytes=133

2015-04-25T08:06:23.172282+00:00 heroku[router]: at=info method=GET path="/gfx/logo.png" host=keplar
blog4.herokuapp.com request_id=abd50fb2-6861-47bb-b884-6c367d35d857 fwd="117.102.24.185" dyno=web.1
connect=0ms service=8ms status=304 bytes=133

2015-04-25T08:06:23.629123+00:00 heroku[router]: at=info method=GET path="/gfx/logo-nettuts.png" hos
t=keplarblog4.herokuapp.com request_id=77932ef2-842e-453d-b12b-fc634394ff91 fwd="117.102.24.185" dyn
o=web.1 connect=0ms service=4ms status=304 bytes=133

2015-04-25T08:06:23.701511+00:00 heroku[router]: at=info method=GET path="/style.less" host=keplarbl
og4.herokuapp.com request_id=d28896bf-abef-4d8c-bb79-a6a3788435aa fwd="117.102.24.185" dyno=web.1 co
nnect=1ms service=3ms status=304 bytes=133

2015-04-25T08:06:23.627140+00:00 heroku[router]: at=info method=GET path="/gfx/frog.jpg" host=keplar
blog4.herokuapp.com request_id=6a33e5cd-c014-4e92-a60e-2d5ebeb1b866 fwd="117.102.24.185" dyno=web.1
connect=0ms service=7ms status=304 bytes=133

2015-04-25T08:06:24.014723+00:00 heroku[router]: at=info method=GET path="/gfx/bg-header.png" host=k
eplarblog4.herokuapp.com request_id=9ab6b848-e862-4632-820d-fb9e900f6b61 fwd="117.102.24.185" dyno=w
eb.1 connect=0ms service=7ms status=304 bytes=133

2015-04-25T08:06:24.027774+00:00 heroku[router]: at=info method=GET path="/gfx/bg-footer.png" host=k
eplarblog4.herokuapp.com request_id=2fcb8907-9790-4c7c-84e9-e7f00f461110 fwd="117.102.24.185" dyno=w
eb.1 connect=1ms service=3ms status=304 bytes=133

2015-04-25T08:06:24.007494+00:00 heroku[router]: at=info method=GET path="/gfx/bg.png" host=keplarbl
og4.herokuapp.com request_id=5b210759-353a-41a1-b66a-47a4f4da16d8 fwd="117.102.24.185" dyno=web.1 co
nnect=1ms service=7ms status=304 bytes=133

2015-04-25T08:06:24.353070+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=keplarb
log4.herokuapp.com request_id=8fc598ef-7e97-4873-94f1-09505a49088b fwd="117.102.24.185" dyno=web.1 c
onnect=0ms service=5ms status=304 bytes=133

2015-04-25T08:07:33.733667+00:00 heroku[router]: at=info method=POST path="/users" host=keplarblog4.
herokuapp.com request_id=d9d4685f-9aab-404a-874d-ebcd3f543573 fwd="117.102.24.185" dyno=web.1 connec
t=0ms service=3262ms status=302 bytes=1033

2015-04-25T08:07:34.035847+00:00 heroku[router]: at=info method=GET path="/" host=keplarblog4.heroku
app.com request_id=d090ea4d-20e4-4ca4-a668-ecb0831e2962 fwd="117.102.24.185" dyno=web.1 connect=0ms
service=18ms status=200 bytes=3049

2015-04-25T08:08:10.065104+00:00 heroku[router]: at=info method=GET path="/users/5gOyuWA3-rqDG8WhZMJ
YjQ/confirm_email" host=keplarblog4.herokuapp.com request_id=ee307920-1157-4037-8d89-7d6b652965be fw
d="117.102.24.185" dyno=web.1 connect=0ms service=27ms status=500 bytes=1754

我试图拖尾我的heroku日志(heroku logs --tail),我在注册时监视日志。它在我的日志上给了我500状态错误。

website1.com  
website2word1.com  
webword2site3.com  

提前致谢!

0 个答案:

没有答案